Skip to content

Commit

Permalink
Merge pull request #798 from auth0/jose4
Browse files Browse the repository at this point in the history
[SDK-3570] Upgrade to Jose@4
  • Loading branch information
adamjmcgrath committed Sep 7, 2022
2 parents f8ceb4f + 78f91e1 commit b4e96e5
Show file tree
Hide file tree
Showing 39 changed files with 534 additions and 511 deletions.
39 changes: 33 additions & 6 deletions V2_MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,37 @@

Guide to migrating from `1.x` to `2.x`

- [`getSession` now returns a `Promise`](#getsession-now-returns-a-promise)
- [`updateUser` has been added](#updateuser-has-been-added)
- [`getServerSidePropsWrapper` has been removed](#getserversidepropswrapper-has-been-removed)
- [Profile API route no longer returns a 401](#profile-api-route-no-longer-returns-a-401)

## `getSession` now returns a `Promise`

### Before

```js
// /pages/api/my-api
import { getSession } from '@auth0/nextjs-auth0';

function myApiRoute(req, res) {
const session = getSession(req, res);
// ...
}
```

### After

```js
// /pages/api/my-api
import { getSession } from '@auth0/nextjs-auth0';

async function myApiRoute(req, res) {
const session = await getSession(req, res);
// ...
}
```

## `updateUser` has been added

### Before
Expand All @@ -29,17 +56,17 @@ function myApiRoute(req, res) {

We've introduced a new `updateUser` method which must be explicitly invoked in order to update the session's user.

This will immediately serialise the session and write it to the cookie.
This will immediately serialise the session, write it to the cookie and return a `Promise`.

```js
// /pages/api/update-user
import { getSession, updateUser } from '@auth0/nextjs-auth0';

function myApiRoute(req, res) {
const { user } = getSession(req, res);
async function myApiRoute(req, res) {
const { user } = await getSession(req, res);
// The session is updated, serialized and the cookie is updated
// everytime you call `updateUser`.
updateUser(req, res, { ...user, foo: 'bar' });
await updateUser(req, res, { ...user, foo: 'bar' });
res.json({ success: true });
}
```
Expand All @@ -51,7 +78,7 @@ Because the process of modifying the session is now explicit, you no longer have
### Before

```js
export const getServerSideProps = getServerSidePropsWrapper(async (ctx) => {
export const getServerSideProps = getServerSidePropsWrapper((ctx) => {
const session = getSession(ctx.req, ctx.res);
if (session) {
// User is authenticated
Expand All @@ -65,7 +92,7 @@ export const getServerSideProps = getServerSidePropsWrapper(async (ctx) => {

```js
export const getServerSideProps = async (ctx) => {
const session = getSession(ctx.req, ctx.res);
const session = await getSession(ctx.req, ctx.res);
if (session) {
// User is authenticated
} else {
Expand Down
104 changes: 45 additions & 59 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,12 @@
"typescript": "^4.1.3"
},
"dependencies": {
"base64url": "^3.0.1",
"@panva/hkdf": "^1.0.2",
"cookie": "^0.5.0",
"debug": "^4.3.4",
"futoin-hkdf": "^1.5.0",
"http-errors": "^1.8.1",
"joi": "^17.6.0",
"jose": "^2.0.5",
"jose": "^4.9.2",
"openid-client": "^4.9.1",
"tslib": "^2.4.0",
"url-join": "^4.0.1"
Expand Down
Loading

0 comments on commit b4e96e5

Please sign in to comment.