Skip to content

Commit 2d8ffa6

Browse files
committed
Update readme
1 parent 06bcca7 commit 2d8ffa6

1 file changed

Lines changed: 66 additions & 3 deletions

File tree

README.md

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,20 @@ First, use the CLI tool to generate your key pair:
2929
$ npx @takeshape/next-auth-all-access generate-keys
3030
```
3131

32-
Next, import the library and wrap your `NextAuth` instance with it:
32+
### Using `next-auth` v4 and the `pages` folder
33+
34+
Import the library and wrap your `NextAuth` instance with it:
3335

3436
```typescript
3537
import createNextAuthAllAccess from '@takeshape/next-auth-all-access'
3638
import NextAuth from 'next-auth'
3739
import Auth0Provider from 'next-auth/providers/auth0'
38-
import path from 'path'
40+
import jwks from '../../keys/jwks.json';
3941

4042
const withAllAccess = createNextAuthAllAccess({
4143
issuer: 'https://example.com/',
42-
jwksPath: path.resolve(process.cwd(), './keys/jwks.json'),
44+
origin: 'https://example.com/',
45+
jwks,
4346
clients: [
4447
{
4548
id: 'my-api',
@@ -66,6 +69,66 @@ export default withAllAccess(NextAuth, {
6669
})
6770
```
6871

72+
### Using `next-auth` v5 and the `app` folder
73+
74+
> [!IMPORTANT]
75+
> When using this with `next-auth` v5, in version 1.1.0 and above, you will
76+
> need to create a separate route for the all-access API endpoints. Earlier
77+
> versions would register these under the `next-auth` route.
78+
79+
Create your `next-auth-all-access` instance and export it:
80+
81+
```typescript title=app/auth-all-access.ts
82+
import createNextAuthAllAccess from '@takeshape/next-auth-all-access/v5';
83+
import jwks from '../../keys/jwks.json';
84+
85+
export const {
86+
handlers: { GET },
87+
withAllAccess
88+
} = createNextAuthAllAccess({
89+
issuer: 'https://example.com/',
90+
origin: 'https://example.com/',
91+
jwks,
92+
clients: [
93+
{
94+
id: 'my-api',
95+
audience: 'https://my-api.com/posts',
96+
expiration: '6h',
97+
// Optional whitelist — `exp` and `iat` will always be included
98+
allowedClaims: ['email', 'sub'],
99+
// Optional rename
100+
renameClaims: {
101+
foo: 'bar',
102+
},
103+
},
104+
]
105+
});
106+
```
107+
108+
```typescript title=app/auth.ts
109+
import Auth0Provider from 'next-auth/providers/auth0'
110+
import { withAllAccess } from './auth-all-access';
111+
112+
export const {
113+
handlers: { GET, POST },
114+
auth
115+
} = NextAuth(withAllAccess({
116+
providers: [
117+
Auth0Provider({
118+
clientId: process.env.AUTH0_ID,
119+
clientSecret: process.env.AUTH0_SECRET,
120+
issuer: process.env.AUTH0_ISSUER,
121+
}),
122+
]
123+
}));
124+
```
125+
126+
```typescript title=app/api/oidc/[...allaccess]/route.ts
127+
export { GET } from '@/lib/auth-all-access';
128+
```
129+
130+
## Client Integration
131+
69132
`NextAuthAllAccess` will add any configured client tokens to the session object
70133
under the `allAccess` property. In the example above your session would contain
71134
properties that look like this:

0 commit comments

Comments
 (0)