@@ -30,17 +30,49 @@ cp .env.local.example .env.local
30
30
npx auth secret
31
31
```
32
32
33
- In the ` auth.ts ` file, replace the ` profiders ` array with just Ory:
33
+ In the ` auth.ts ` file, replace the ` providers ` array with just Ory:
34
34
35
35
``` ts title="auth.ts"
36
- import { OryNetworkCta } from " ./ory-network-cta"
36
+ import { Profile } from " next-auth"
37
+ import { OIDCConfig } from " next-auth/providers"
38
+
37
39
export const config = {
38
40
theme: { logo: " https://authjs.dev/img/logo-sm.png" },
39
41
providers: [
40
- // Apple,
41
- // AzureB2C,
42
- Ory ,
42
+ {
43
+ id: " ory" ,
44
+ name: " Ory" ,
45
+ type: " oidc" ,
46
+ issuer: process .env .ORY_SDK_URL ,
47
+ clientId: process .env .ORY_CLIENT_ID ,
48
+ clientSecret: process .env .ORY_CLIENT_SECRET ,
49
+ checks: [" pkce" as never , " state" as never ],
50
+ token: {
51
+ idToken: true ,
52
+ },
53
+ } satisfies OIDCConfig <Profile >,
43
54
],
55
+ callbacks: {
56
+ authorized({ request , auth }) {
57
+ const { pathname } = request .nextUrl
58
+ if (pathname === " /middleware-example" ) return !! auth
59
+ return true
60
+ },
61
+ session({ session , token }) {
62
+ session .sid = token .sid as string
63
+ session .idToken = token .idToken as string
64
+ return session
65
+ },
66
+ jwt({ token , user , account , profile , isNewUser }) {
67
+ if (profile ) {
68
+ token .sid = profile .sid
69
+ }
70
+ if (account ) {
71
+ token .idToken = account .id_token
72
+ }
73
+ return token
74
+ },
75
+ },
44
76
// ...
45
77
}
46
78
```
@@ -103,7 +135,7 @@ AUTH_ORY_ISSUER=...
103
135
Now everything is set up and you can run ` npm run dev ` to start the app and click on the top left "Sign in" button to start the
104
136
login flow.
105
137
106
- ## Going to production
138
+ ## Go to production
107
139
108
140
When you are ready to go to production, you need to update the redirect URL in the Ory client settings to the production URL of
109
141
your Next.js application.
0 commit comments