Skip to content

Commit b831c8b

Browse files
guabunandan-bhat
authored andcommitted
re-add older migration guides
1 parent 7ef0f04 commit b831c8b

File tree

3 files changed

+727
-0
lines changed

3 files changed

+727
-0
lines changed

V1_MIGRATION_GUIDE.md

+295
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,295 @@
1+
# V1 Migration Guide
2+
3+
Guide to migrating from `0.x` to `1.x`
4+
5+
### Config changes
6+
7+
> Note: If you only use environment variables to configure the SDK, you don't need to create an instance of the SDK. You can use the named exports (`handleAuth`, `getSession`) directly from `@auth0/nextjs-auth` and they will lazily create an instance of the SDK for you, and configure it using the following [environment variables](https://auth0.github.io/nextjs-auth0/modules/config.html). See the [Basic setup](./EXAMPLES.md#basic-setup) as an example.
8+
9+
If you still want to create the SDK instance yourself, note that the configuration options have changed as follows.
10+
11+
- `domain` is now `issuerBaseURL` and should be a fully qualified url.
12+
- `clientId` is now `clientID`
13+
- `redirectUri` is now `routes.callback` and is a relative path, the full url is constructed using `baseURL`
14+
- `postLogoutRedirectUri` is now `routes.postLogoutRedirect` and can be a relative path, the full url is constructed using `baseURL` if no host is provided.
15+
- `scope` and `audience` are optional and should be passed to `authorizationParams`
16+
- `session.cookieSecret` is now `secret`
17+
- `session.cookieName` is now `session.name`
18+
- `session.cookieSameSite` is now `session.cookie.sameSite`
19+
- `session.cookieLifetime` is now `session.rollingDuration` and defaults to 24 hrs rolling and 7 days absolute
20+
- `session.cookiePath` is now `session.cookie.path` and defaults to `'/'`
21+
- `session.cookieDomain` is now `session.cookie.domain`
22+
- `session.storeIdToken`, `session.storeAccessToken`, `session.storeRefreshToken` are no longer options. All tokens are stored by default, to remove anything from the session see [the afterCallback option in handleCallback](https://auth0.github.io/nextjs-auth0/modules/handlers_callback.html#modify-the-session-after-login).
23+
- `oidcClient.httpTimeout` is now `httpTimeout` and defaults to 5000 ms
24+
- `oidcClient.clockTolerance` is now `clockTolerance` defined in secs and defaults to 60 secs
25+
26+
#### Before
27+
28+
```js
29+
import { initAuth0 } from "@auth0/nextjs-auth0"
30+
31+
export default initAuth0({
32+
domain: "my-tenant.auth0.com",
33+
clientId: "MY_CLIENT_ID",
34+
clientSecret: "MY_CLIENT_SECRET",
35+
scope: "openid profile",
36+
audience: "MY_AUDIENCE",
37+
redirectUri: "http://localhost:3000/api/callback",
38+
postLogoutRedirectUri: "http://localhost:3000/",
39+
session: {
40+
cookieSecret: "some_very_long_secret_string",
41+
cookieLifetime: 60 * 60 * 8,
42+
storeIdToken: false,
43+
storeRefreshToken: false,
44+
storeAccessToken: false,
45+
},
46+
oidcClient: {
47+
clockTolerance: 10000,
48+
httpTimeout: 2500,
49+
},
50+
})
51+
```
52+
53+
#### After
54+
55+
```js
56+
import { initAuth0 } from "@auth0/nextjs-auth0"
57+
58+
export default initAuth0({
59+
baseURL: "http://localhost:3000",
60+
issuerBaseURL: "https://my-tenant.auth0.com",
61+
clientID: "MY_CLIENT_ID",
62+
clientSecret: "MY_CLIENT_SECRET",
63+
secret: "some_very_long_secret_string",
64+
clockTolerance: 60,
65+
httpTimeout: 5000,
66+
authorizationParams: {
67+
scope: "openid profile email",
68+
audience: "MY_AUDIENCE",
69+
},
70+
routes: {
71+
callback: "/api/callback",
72+
postLogoutRedirect: "/",
73+
},
74+
session: {
75+
rollingDuration: 60 * 60 * 24,
76+
absoluteDuration: 60 * 60 * 24 * 7,
77+
},
78+
})
79+
```
80+
81+
See the API docs for a [full list of configuration options](https://auth0.github.io/nextjs-auth0/modules/config.html).
82+
83+
### getSession
84+
85+
`getSession` now requires a response as well as a request argument (any updates you make to the session object will now be persisted).
86+
87+
#### Before
88+
89+
```js
90+
// pages/api/shows.js
91+
import auth0 from "../../lib/auth0"
92+
93+
export default function shows(req, res) {
94+
const session = auth0.getSession(req)
95+
// ...
96+
}
97+
```
98+
99+
#### After
100+
101+
```js
102+
// pages/api/shows.js
103+
import auth0 from "../../lib/auth0"
104+
105+
export default function shows(req, res) {
106+
const session = auth0.getSession(req, res) // Note: the extra argument
107+
// ...
108+
}
109+
```
110+
111+
See the [getSession docs](https://auth0.github.io/nextjs-auth0/modules/session_get_session.html).
112+
113+
### getAccessToken
114+
115+
`tokenCache` has been removed in favor of a single `getAccessToken` method.
116+
117+
### Before
118+
119+
```js
120+
// pages/api/shows.js
121+
import auth0 from "../../lib/auth0"
122+
123+
export default async function shows(req, res) {
124+
const tokenCache = auth0.tokenCache(req, res)
125+
const { accessToken } = await tokenCache.getAccessToken({
126+
scopes: ["read:shows"],
127+
})
128+
// ...
129+
}
130+
```
131+
132+
### After
133+
134+
```js
135+
// pages/api/shows.js
136+
import auth0 from "../../lib/auth0"
137+
138+
export default async function shows(req, res) {
139+
const { accessToken } = await auth0.getAccessToken(req, res, {
140+
scopes: ["read:shows"],
141+
})
142+
// ...
143+
}
144+
```
145+
146+
See the [getAccessToken docs](https://auth0.github.io/nextjs-auth0/modules/session_get_access_token.html).
147+
148+
### handleLogin
149+
150+
The options passed to `handleLogin` have changed.
151+
152+
- `authParams` is now `authorizationParams`
153+
- `redirectTo` is now `returnTo`
154+
155+
#### Before
156+
157+
```js
158+
// pages/api/login.js
159+
import auth0 from "../../utils/auth0"
160+
161+
export default async function login(req, res) {
162+
try {
163+
await auth0.handleLogin(req, res, {
164+
authParams: {
165+
login_hint: "[email protected]",
166+
ui_locales: "nl",
167+
scope: "some other scope",
168+
foo: "bar",
169+
},
170+
redirectTo: "/custom-url",
171+
})
172+
} catch (error) {
173+
console.error(error)
174+
res.status(error.status || 500).end(error.message)
175+
}
176+
}
177+
```
178+
179+
#### After
180+
181+
```js
182+
// pages/api/login.js
183+
import auth0 from "../../utils/auth0"
184+
185+
export default async function login(req, res) {
186+
try {
187+
await auth0.handleLogin(req, res, {
188+
authorizationParams: {
189+
login_hint: "[email protected]",
190+
ui_locales: "nl",
191+
scope: "some other scope",
192+
foo: "bar",
193+
},
194+
returnTo: "/custom-url",
195+
})
196+
} catch (error) {
197+
console.error(error)
198+
res.status(error.status || 500).end(error.message)
199+
}
200+
}
201+
```
202+
203+
See the [handleLogin docs](https://auth0.github.io/nextjs-auth0/modules/handlers_login.html).
204+
205+
### handleLogout
206+
207+
The options passed to `handleLogout` have changed.
208+
209+
- `redirectTo` is now `returnTo`
210+
211+
#### Before
212+
213+
```js
214+
// pages/api/logout.js
215+
import auth0 from "../../utils/auth0"
216+
217+
export default async function logout(req, res) {
218+
try {
219+
await auth0.handleLogout(req, res, {
220+
redirectTo: "/custom-url",
221+
})
222+
} catch (error) {
223+
console.error(error)
224+
res.status(error.status || 500).end(error.message)
225+
}
226+
}
227+
```
228+
229+
#### After
230+
231+
```js
232+
// pages/api/logout.js
233+
import auth0 from "../../utils/auth0"
234+
235+
export default async function logout(req, res) {
236+
try {
237+
await auth0.handleLogout(req, res, {
238+
returnTo: "/custom-url",
239+
})
240+
} catch (error) {
241+
console.error(error)
242+
res.status(error.status || 500).end(error.message)
243+
}
244+
}
245+
```
246+
247+
See the [handleLogout docs](https://auth0.github.io/nextjs-auth0/modules/handlers_logout.html).
248+
249+
### handleCallback
250+
251+
The options passed to `handleCallback` have changed.
252+
253+
- `onUserLoaded` is now `afterCallback`
254+
255+
#### Before
256+
257+
```js
258+
// pages/api/callback.js
259+
import auth0 from "../../utils/auth0"
260+
261+
export default async function callback(req, res) {
262+
try {
263+
await auth0.handleCallback(req, res, {
264+
async onUserLoaded(req, res, session, state) {
265+
return session
266+
},
267+
})
268+
} catch (error) {
269+
console.error(error)
270+
res.status(error.status || 500).end(error.message)
271+
}
272+
}
273+
```
274+
275+
#### After
276+
277+
```js
278+
// pages/api/callback.js
279+
import auth0 from "../../utils/auth0"
280+
281+
export default async function callback(req, res) {
282+
try {
283+
await auth0.handleCallback(req, res, {
284+
async afterCallback(req, res, session, state) {
285+
return session
286+
},
287+
})
288+
} catch (error) {
289+
console.error(error)
290+
res.status(error.status || 500).end(error.message)
291+
}
292+
}
293+
```
294+
295+
See the [handleCallback docs](https://auth0.github.io/nextjs-auth0/modules/handlers_callback.html).

0 commit comments

Comments
 (0)