Skip to content

Commit e5bfbed

Browse files
balazsorban44thomas-desmondndom91pCyril
authoredDec 12, 2022
Sync (#2)
* fix(core): properly construct url (nextauthjs#5984) * chore(release): bump package version(s) [skip ci] * fix(core): add protocol if missing * fix(core): throw error if no action can be determined * test(core): fix test * chore(release): bump package version(s) [skip ci] * chore(docs): add new tutorial (nextauthjs#5604) Co-authored-by: Nico Domino <[email protected]> * fix(core): handle `Request` -> `Response` regressions (nextauthjs#5991) * fix(next): don't override `Content-Type` by `unstable_getServerSession` * fix(core): handle `,` while setting `set-cookie` * chore(release): bump package version(s) [skip ci] * fix(sequelize): increase sequelize `id_token` column length (nextauthjs#5929) Co-authored-by: Nico Domino <[email protected]> * fix(core): correct status code when returning redirects (nextauthjs#6004) * fix(core): correctly set status when returning redirect * update tests * forward other headers * update test * remove default 200 status * fix(core): host detection/NEXTAUTH_URL (nextauthjs#6007) * rename `host` to `origin` internally * rename `userOptions` to `authOptions` internally * use object for `headers` internally * default `method` to GET * simplify `unstable_getServerSession` * allow optional headers * revert middleware * wip getURL * revert host detection * use old `detectHost` * fix/add some tests wip * move more to core, refactor getURL * better type auth actions * fix custom path support (w/ api/auth) * add `getURL` tests * fix email tests * fix assert tests * custom base without api/auth, with trailing slash * remove parseUrl from assert.ts * return 400 when wrong url * fix tests * refactor * fix protocol in dev * fix tests * fix custom url handling * add todo comments * chore(release): bump package version(s) [skip ci] * update lock file * fix(next): correctly bundle next-auth/middleware fixes nextauthjs#6025 * fix(core): preserve incoming set cookies (nextauthjs#6029) * fix(core): preserve `set-cookie` by the user * add test * improve req/res mocking * refactor * fix comment typo * chore(release): bump package version(s) [skip ci] * make logos optional * sync with `next-auth` * clean up `next-auth/edge` * sync Co-authored-by: Balázs Orbán <[email protected]> Co-authored-by: Thomas Desmond <[email protected]> Co-authored-by: Nico Domino <[email protected]> Co-authored-by: Cyril Perraud <[email protected]>

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+933
-394
lines changed
 

‎apps/dev/pages/api/auth/[...nextauth].ts

+17-18
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import Slack from "next-auth-core/providers/slack"
3131
import Spotify from "next-auth-core/providers/spotify"
3232
import Trakt from "next-auth-core/providers/trakt"
3333
import Twitch from "next-auth-core/providers/twitch"
34-
import Twitter, { TwitterLegacy } from "next-auth-core/providers/twitter"
34+
import Twitter from "next-auth-core/providers/twitter"
3535
import Vk from "next-auth-core/providers/vk"
3636
import Wikimedia from "next-auth-core/providers/wikimedia"
3737
import WorkOS from "next-auth-core/providers/workos"
@@ -113,7 +113,7 @@ export const authOptions: AuthOptions = {
113113
Spotify({ clientId: process.env.SPOTIFY_ID, clientSecret: process.env.SPOTIFY_SECRET }),
114114
Trakt({ clientId: process.env.TRAKT_ID, clientSecret: process.env.TRAKT_SECRET }),
115115
Twitch({ clientId: process.env.TWITCH_ID, clientSecret: process.env.TWITCH_SECRET }),
116-
Twitter({ version: "2.0", clientId: process.env.TWITTER_ID, clientSecret: process.env.TWITTER_SECRET }),
116+
Twitter({ clientId: process.env.TWITTER_ID, clientSecret: process.env.TWITTER_SECRET }),
117117
// TwitterLegacy({ clientId: process.env.TWITTER_LEGACY_ID, clientSecret: process.env.TWITTER_LEGACY_SECRET }),
118118
Vk({ clientId: process.env.VK_ID, clientSecret: process.env.VK_SECRET }),
119119
Wikimedia({ clientId: process.env.WIKIMEDIA_ID, clientSecret: process.env.WIKIMEDIA_SECRET }),
@@ -132,25 +132,24 @@ if (authOptions.adapter) {
132132

133133
// TODO: move to next-auth/edge
134134
function Auth(...args: any[]) {
135-
if (args.length === 1)
136-
return async (req: Request) => {
137-
args[0].secret ??= process.env.NEXTAUTH_SECRET
138-
139-
// TODO: remove when `next-auth/react` sends `X-Auth-Return-Redirect`
140-
const shouldRedirect = req.method === "POST" && req.headers.get("Content-Type") === "application/json" ? (await req.clone().json()).json : false
141-
142-
// TODO: This can be directly in core
143-
const res = await AuthHandler(req, args[0])
144-
if (req.headers.get("X-Auth-Return-Redirect") || shouldRedirect) {
145-
const url = res.headers.get("Location")
146-
res.headers.delete("Location")
147-
return new Response(JSON.stringify({ url }), res)
148-
}
149-
return res
135+
const envSecret = process.env.NEXTAUTH_SECRET
136+
const envTrustHost = !!(process.env.NEXTAUTH_URL ?? process.env.AUTH_TRUST_HOST ?? process.env.VERCEL ?? process.env.NODE_ENV !== "production")
137+
if (args.length === 1) {
138+
return (req: Request) => {
139+
args[0].secret ??= envSecret
140+
args[0].trustHost ??= envTrustHost
141+
return AuthHandler(req, args[0])
150142
}
143+
}
144+
args[1].secret ??= envSecret
145+
args[1].trustHost ??= envTrustHost
151146
return AuthHandler(args[0], args[1])
152147
}
153148

154-
export default Auth(authOptions)
149+
// export default Auth(authOptions)
150+
151+
export default function handle(request: Request) {
152+
return Auth(request, authOptions)
153+
}
155154

156155
export const config = { runtime: "experimental-edge" }

‎docs/docs/tutorials.md

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ title: Tutorials and Explainers
4646
- Learn how to use Sign-In With Ethereum to authenticate your users with their existing Ethereum wallets - identifiers they personally control.
4747
- Example application: [spruceid/siwe-next-auth-example](https://github.com/spruceid/siwe-next-auth-example)
4848

49+
#### [Next.js Authentication with Okta and NextAuth.js 4.0](https://thetombomb.com/posts/nextjs-nextauth-okta) <svg xmlns="http://www.w3.org/2000/svg" style={{ marginLeft: '5px', marginBottom:'-6px'}} height="20" width="20" fill="none" viewBox="0 0 24 24" stroke="currentColor"><title>External</title> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" /> </svg>
50+
51+
- Learn how to perform authentication with an OIDC Application in Okta and NextAuth.js.
52+
4953
## Fullstack
5054

5155
#### [Build a FullStack App with Next.js, NextAuth.js, Supabase & Prisma](https://themodern.dev/courses/build-a-fullstack-app-with-nextjs-supabase-and-prisma-322389284337222224) <svg xmlns="http://www.w3.org/2000/svg" style={{ marginLeft: '5px', marginBottom:'-6px'}} height="20" width="20" fill="none" viewBox="0 0 24 24" stroke="currentColor"><title>External</title> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" /> </svg>

0 commit comments

Comments
 (0)
Please sign in to comment.