Skip to content

Commit

Permalink
rm userData middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
neurosnap committed Jan 21, 2022
1 parent 24192bd commit f0b27a3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 24 deletions.
17 changes: 2 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ yarn add remix-middleware
```

```ts
// ./app/middleware.ts
// ./app/middleware.server.ts
export const mdw = createMiddleware();

mdw.use(async (ctx, next) => {
Expand Down Expand Up @@ -101,11 +101,10 @@ export const loader: LoaderFunction = (props) =>

## remix-auth

We built a couple middleware that will help interacting with [remix-auth](https://github.com/sergiodxa/remix-auth)
We built a middleware that will help interacting with [remix-auth](https://github.com/sergiodxa/remix-auth)
more streamlined.

- isAuthenticated - activates `authenticator.isAuthenticated`
- userData - automatically assigns the user object to the remix response object

Setting up `remix-auth`

Expand Down Expand Up @@ -185,15 +184,3 @@ import { authed, unauthed } from '~/middleware.ts';
// `.run()` doesn't need any middleware, it'll run without it
export const loader = (props) => unauthed.run(props);
```

`userData` middleware

```ts
import { userData } from 'remux-middleware';
import { authed } from '~/middleware.ts';

// if you just want user data in the loader response
export const loader = (props) => authed.run(props, userData)
// this will automatically add `user` to the response object
// ctx.response.user = { ... }
```
9 changes: 0 additions & 9 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,6 @@ export function createMiddleware<CurCtx extends Ctx = Ctx>() {
};
}

export async function userData<CurCtx extends AuthCtx = AuthCtx>(
ctx: CurCtx,
next: Next,
) {
if (!ctx.response) ctx.response = {};
ctx.response.user = ctx.user;
await next();
}

export function isAuthenticated<U>(
auth: Authenticator<U>,
options?: { successRedirect?: never; failureRedirect?: never },
Expand Down

0 comments on commit f0b27a3

Please sign in to comment.