Skip to content

Commit

Permalink
fix: update default callbacks.redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsorban44 committed Apr 12, 2022
1 parent 7a4bf03 commit 6e15bdc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions docs/docs/configuration/callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ The default redirect callback looks like this:
...
callbacks: {
async redirect({ url, baseUrl }) {
if (url.startsWith(baseUrl)) return url
// Allows relative callback URLs
else if (url.startsWith("/")) return new URL(url, baseUrl).toString()
if (url.startsWith("/")) return new URL(url, baseUrl).toString()
// Allows callback URLs on the same origin
else if (new URL(url).origin === baseUrl) return url
return baseUrl
}
}
Expand All @@ -104,7 +105,7 @@ The redirect callback may be invoked more than once in the same flow.
## JWT callback

This callback is called whenever a JSON Web Token is created (i.e. at sign
in) or updated (i.e whenever a session is accessed in the client). The returned value will be [encrypted](/configuration/options#jwt), and it is stored in a cookie.
in) or updated (i.e whenever a session is accessed in the client). The returned value will be [signed and optionally encrypted](/configuration/options#jwt), and it is stored in a cookie.

Requests to `/api/auth/signin`, `/api/auth/session` and calls to `getSession()`, `useSession()` will invoke this function, but only if you are using a [JWT session](/configuration/options#session). This method is not invoked when you persist sessions in a database.

Expand Down
4 changes: 2 additions & 2 deletions packages/next-auth/src/core/lib/default-callbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export const defaultCallbacks: CallbacksOptions = {
return true
},
redirect({ url, baseUrl }) {
if (url.startsWith(baseUrl)) return url
else if (url.startsWith("/")) return new URL(url, baseUrl).toString()
if (url.startsWith("/")) return new URL(url, baseUrl).toString()
else if (new URL(url).origin === baseUrl) return url
return baseUrl
},
session({ session }) {
Expand Down

1 comment on commit 6e15bdc

@vercel
Copy link

@vercel vercel bot commented on 6e15bdc Apr 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please # to comment.