Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nextjs): introduce next-auth v5 #7443

Merged
merged 339 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
339 commits
Select commit Hold shift + click to select a range
46f622a
Merge branch 'main' into feat/nextjs-auth
balazsorban44 May 4, 2023
c411c6f
update gitignore
balazsorban44 May 4, 2023
18a4e8b
update turbo
balazsorban44 May 4, 2023
440317a
update turbo
balazsorban44 May 4, 2023
52c04fe
update turbo
balazsorban44 May 4, 2023
3c23a4f
add docs
balazsorban44 May 4, 2023
6f5a503
chore: use `@ts-ignore`
balazsorban44 May 4, 2023
c47a2eb
Merge branch 'main' into feat/nextjs-auth
balazsorban44 May 4, 2023
a7991ae
revert
balazsorban44 May 4, 2023
0b80c65
update lock file
balazsorban44 May 4, 2023
d6bc65f
chore: support release any package as experimental
balazsorban44 May 4, 2023
0afb179
Merge branch 'main' into feat/nextjs-auth
balazsorban44 May 4, 2023
99247ce
chore: separate manual release job
balazsorban44 May 4, 2023
7fae874
Merge branch 'main' into feat/nextjs-auth
balazsorban44 May 4, 2023
e0b5f18
chore: skip test for manual release
balazsorban44 May 4, 2023
601c8c9
Merge branch 'main' into feat/nextjs-auth
balazsorban44 May 4, 2023
eaf5080
chore: tweak
balazsorban44 May 4, 2023
8f40883
Merge branch 'main' into feat/nextjs-auth
balazsorban44 May 4, 2023
aaff906
add readme
balazsorban44 May 4, 2023
e4d568c
fix redirects
balazsorban44 May 4, 2023
8f416b6
chore: tweaks
balazsorban44 May 4, 2023
587d366
Merge branch 'main' into feat/nextjs-auth
balazsorban44 May 4, 2023
65fe0ef
fix imports
balazsorban44 May 4, 2023
3ba510c
forward all `set-cookie` headers
balazsorban44 May 4, 2023
af81776
upgrade dev app
balazsorban44 May 4, 2023
8cfd1ae
improve docs
balazsorban44 May 5, 2023
c470960
docs
balazsorban44 May 5, 2023
7da3256
docs
balazsorban44 May 5, 2023
b17c5de
add installation
balazsorban44 May 5, 2023
24e8100
move
balazsorban44 May 5, 2023
5fb4caa
whitespace
balazsorban44 May 5, 2023
b96f013
chore: tweak manual release version
balazsorban44 May 5, 2023
b17dc76
Merge branch 'main' into feat/nextjs-auth
balazsorban44 May 5, 2023
436d46a
tweak docs
balazsorban44 May 5, 2023
bb4d5ce
update dev app
balazsorban44 May 5, 2023
bac8b8d
add `getServerSession`, simplify `auth()` return
balazsorban44 May 5, 2023
a7e0226
fix value
balazsorban44 May 5, 2023
50bf545
feat(docs): add upgrdae-to-v5.md page
ndom91 May 7, 2023
df1e557
don't require passing `headers()` to `auth()`
balazsorban44 May 7, 2023
bf10ef2
remove `getServerSession`
balazsorban44 May 7, 2023
26122b4
fix passing req to `fetchData`
balazsorban44 May 7, 2023
95c80b4
Merge branch 'feat/nextjs-auth' of github.com:nextauthjs/next-auth in…
balazsorban44 May 7, 2023
9212654
fix(docs): markdwon table for API changes
ndom91 May 7, 2023
53e2c60
Merge branch 'feat/nextjs-auth' of ssh://github.com/nextauthjs/next-a…
ndom91 May 7, 2023
61ec4f3
rename react to client
balazsorban44 May 7, 2023
96f0ea2
fix(docs): clean up API table formatting
ndom91 May 7, 2023
5f9f473
update dev app
balazsorban44 May 7, 2023
9e14bb3
Merge branch 'feat/nextjs-auth' of github.com:nextauthjs/next-auth in…
balazsorban44 May 7, 2023
681a8b6
fix: clean up table and add links
ndom91 May 7, 2023
e8a2b36
feat(docs): add example routes and more breaking changes to upgrade-v…
ndom91 May 7, 2023
b4028bd
fix: minor wording changes
ndom91 May 8, 2023
f00ac78
chore: reduce breaking changes on Account mapping
balazsorban44 May 10, 2023
7ffd361
chore: add build to manual publish
balazsorban44 May 10, 2023
e8b4839
Merge branch 'main' into feat/nextjs-auth
balazsorban44 May 10, 2023
a7aafb3
Merge branch 'feat/nextjs-auth' of github.com:nextauthjs/next-auth in…
balazsorban44 May 10, 2023
c336b10
chore: move build to root
balazsorban44 May 10, 2023
c8a8706
Merge branch 'main' into feat/nextjs-auth
balazsorban44 May 10, 2023
ceeb255
feat: add update session to core
balazsorban44 May 10, 2023
66d7179
Merge branch 'feat/update-session-core' into feat/nextjs-auth
balazsorban44 May 10, 2023
f5de6cf
docs(example): update broken link (#7504)
remirobichet May 10, 2023
5f0e00c
resolve default user after jwt callback
balazsorban44 May 10, 2023
8b0276c
Merge branch 'feat/update-session-core' into feat/nextjs-auth
balazsorban44 May 10, 2023
af5df4c
test update
balazsorban44 May 10, 2023
344346c
fix syntax
balazsorban44 May 10, 2023
cca94bf
feat: add update session to core (#7505)
balazsorban44 May 10, 2023
ca5f5bd
Merge branch 'main' into feat/nextjs-auth
balazsorban44 May 10, 2023
7f4d81e
tweak docs
balazsorban44 May 11, 2023
7cd3bad
support Node.js-like environment with `getServerSession`
balazsorban44 May 11, 2023
c53b9f7
update dev app
balazsorban44 May 11, 2023
b826c64
merge `getServerSession` and `auth`
balazsorban44 May 11, 2023
3641972
update dev app
balazsorban44 May 11, 2023
1a6b971
migration guide tweaks
balazsorban44 May 11, 2023
3c5ae44
tweak migration guide
balazsorban44 May 11, 2023
ee746cb
empty commit
balazsorban44 May 11, 2023
6960271
more migration guide tweaks
balazsorban44 May 11, 2023
fbe6bd9
more migration guide
balazsorban44 May 11, 2023
a9b6a63
more migration
balazsorban44 May 11, 2023
375b93c
mention `getToken` in migration
balazsorban44 May 11, 2023
7b09c07
note on `session()` callback
balazsorban44 May 11, 2023
9c02d5f
move note
balazsorban44 May 11, 2023
af30f4e
move
balazsorban44 May 11, 2023
53005b9
cleanup, add comment
balazsorban44 May 11, 2023
c8b1951
add todo
balazsorban44 May 11, 2023
88f632a
revert to image
balazsorban44 May 12, 2023
f62c016
chore: revert `picture` to `image`
balazsorban44 May 12, 2023
7f3ea8f
Merge branch 'main' into feat/nextjs-auth
balazsorban44 May 12, 2023
e4c1665
revert to image
balazsorban44 May 12, 2023
49fe943
revert
balazsorban44 May 12, 2023
d30c21d
mention env variable inferring
balazsorban44 May 12, 2023
3a0f8f3
mention extra fields for database migrations
balazsorban44 May 12, 2023
91fd5f3
fix server component migration
balazsorban44 May 12, 2023
785513e
fix when there is no user-defined callbacks
balazsorban44 May 13, 2023
358caac
add `NextAuthOptions`
balazsorban44 May 14, 2023
ecae35f
mention edge-compatibility
balazsorban44 May 14, 2023
d2543e9
fix page
balazsorban44 May 14, 2023
f62ea8d
remove credentials from examples
balazsorban44 May 14, 2023
b6329dc
autogenerate provider imports
balazsorban44 May 15, 2023
35d9668
fix default export
balazsorban44 May 15, 2023
406e54b
change exports
balazsorban44 May 15, 2023
1ef77a3
publish providers
balazsorban44 May 15, 2023
1f0c2f4
tweak migration guide
balazsorban44 May 15, 2023
91d787b
mention `@auth/core` in breaking changes
balazsorban44 May 15, 2023
789ec13
mention panva in contributors
balazsorban44 May 15, 2023
d8bf293
drop async
balazsorban44 May 15, 2023
e3b5f7c
old/new -> v4/v5
balazsorban44 May 15, 2023
4bf6f73
tweak env inferring docs
balazsorban44 May 15, 2023
927e3a2
make re-export a one-liner
balazsorban44 May 15, 2023
3dc71ac
tweak
balazsorban44 May 15, 2023
0c0061b
drop `@auth/core` from dev app
balazsorban44 May 15, 2023
c5818fe
fix default signin redirect if unauthorized
balazsorban44 May 15, 2023
ed159a0
move upgrade guide to guides
balazsorban44 May 15, 2023
6f89341
add adapter types to migration guide
balazsorban44 May 18, 2023
313f0b7
use NextAuthConfig in env defaults
balazsorban44 May 18, 2023
c5a9b4e
upgrade `next`
balazsorban44 May 18, 2023
2bdf9cf
more specific migration guide links
balazsorban44 May 18, 2023
e69edb7
re-export `NextAuthOptions`
balazsorban44 May 18, 2023
77e45ed
redirect protection for default, `pages` config, NEXTAUTH_URL routes
balazsorban44 May 18, 2023
152ac49
update dev app
balazsorban44 May 18, 2023
220ee41
chore: Move next.config.js file into the correct directory (#7580)
ghoshnirmalya May 18, 2023
4baf2c8
docs: Cypress.Cookies.defaults removed (#7574)
roy9495 May 18, 2023
61dcddf
Merge branch 'main' into feat/nextjs-auth
balazsorban44 May 19, 2023
eeec27f
add `CSRF_experimental`
balazsorban44 May 19, 2023
e53f08e
add database to dev app
balazsorban44 May 19, 2023
bc3ba23
Merge branch 'feat/nextjs-auth' of github.com:nextauthjs/next-auth in…
balazsorban44 May 19, 2023
8373bc9
feat: allow empty `account` mapper
balazsorban44 May 19, 2023
7711eb0
Merge branch 'main' of github.com:nextauthjs/next-auth
balazsorban44 May 19, 2023
d52cd83
Merge branch 'main' into feat/nextjs-auth
balazsorban44 May 19, 2023
d28748b
add comment
balazsorban44 May 19, 2023
3e354fb
expose types
balazsorban44 May 19, 2023
8470744
tweak docs
balazsorban44 May 19, 2023
d111c4d
capitalize
balazsorban44 May 19, 2023
d9a9c57
Apply suggestions from code review
balazsorban44 May 22, 2023
1baad29
tweaks
balazsorban44 May 22, 2023
3f1e0de
fix Route Handler wrapper
balazsorban44 May 22, 2023
11a0e87
fix dev app
balazsorban44 May 22, 2023
a45b278
redirect back to original page after auth
balazsorban44 May 22, 2023
531c5b5
prevent infinite loop on default signin page
balazsorban44 May 22, 2023
030e832
spread session
balazsorban44 May 22, 2023
e040925
update dev app
balazsorban44 May 22, 2023
f625b14
tweaks
balazsorban44 May 22, 2023
39d2806
rephrase, typos
balazsorban44 May 22, 2023
2baf082
update example
balazsorban44 May 22, 2023
de81bb7
tweak docs, remove unused import
balazsorban44 May 23, 2023
62eb457
docs: Update TypeDoc plugins and tweak config (#7653)
tgreyuk May 29, 2023
4989ee3
Update docs/docs/guides/upgrade-to-v5.md
balazsorban44 May 29, 2023
9699746
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Jun 7, 2023
223c646
fix: swallow `BroadcastChannel` missing Next.js error
balazsorban44 Jun 13, 2023
4bb3d41
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Jun 13, 2023
e57e58a
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Jun 13, 2023
5d38692
set up `@auth/nextjs` -> `next-auth` aliasing
balazsorban44 Jun 13, 2023
942f037
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Jun 13, 2023
a6eec2f
fix(docs): Fixed TypeDoc index paths (#7796)
tgreyuk Jun 14, 2023
fdb8ea5
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Jun 14, 2023
722c34b
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Jun 14, 2023
2044689
fix re-export
balazsorban44 Jun 16, 2023
b7162c8
re-rexport default
balazsorban44 Jun 16, 2023
4cd21ea
correct submodule
balazsorban44 Jun 16, 2023
d211b08
re-export types
balazsorban44 Jun 16, 2023
20cbb16
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Jun 16, 2023
198bb20
add docs, bump `next`
balazsorban44 Jun 16, 2023
de74436
update package.json
balazsorban44 Jun 16, 2023
8045eba
properly re-export types
balazsorban44 Jun 16, 2023
f414f2f
use experimental channel
balazsorban44 Jun 20, 2023
9559128
upgrade prisma
balazsorban44 Jun 20, 2023
fd28db0
move imports
balazsorban44 Jun 20, 2023
b53ca00
fix dev dependencies
balazsorban44 Jun 20, 2023
e65faa1
remove `@auth/core` as `next-auth` dependency
balazsorban44 Jun 20, 2023
09d3ce3
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Jun 22, 2023
b9562eb
fix import
balazsorban44 Jun 22, 2023
47dfbcd
fix import (again)
balazsorban44 Jun 22, 2023
1309ee9
always detect secure cookies environment
balazsorban44 Jun 22, 2023
64da9ea
revert
balazsorban44 Jun 22, 2023
179c08d
correctly detect protocol
balazsorban44 Jun 22, 2023
67f3f31
fix typo
balazsorban44 Jun 27, 2023
c1121d9
move `@auth/nextjs` to `next-auth`
balazsorban44 Jun 27, 2023
f438300
rename pr label
balazsorban44 Jun 27, 2023
54b4f96
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Jun 27, 2023
db882e1
update lock file
balazsorban44 Jun 27, 2023
22bd11b
fix indent
balazsorban44 Jun 27, 2023
4306402
tweak migration guide
balazsorban44 Jun 27, 2023
61f9ef7
tweak docs
balazsorban44 Jun 27, 2023
83c4ebd
tweak docs
balazsorban44 Jun 27, 2023
62b9e3f
upgrade next
balazsorban44 Jun 27, 2023
790f761
remove `next-autg/adapters`
balazsorban44 Jun 27, 2023
9d13d2a
remove v4 dev, update next
balazsorban44 Jul 18, 2023
488467f
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Jul 18, 2023
a5a33e5
fix: do not mutate `config`
balazsorban44 Jul 25, 2023
d095234
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Jul 25, 2023
b345135
doc: address review comments in preview
ThangHuuVu Jul 27, 2023
7f33971
doc: update migration guide
ThangHuuVu Jul 29, 2023
07b9578
doc: add tab bars
ThangHuuVu Jul 30, 2023
2196ee2
doc: tweak files
ThangHuuVu Jul 30, 2023
28b2bdf
doc: add tips about AUTH_SECRET
ThangHuuVu Jul 30, 2023
f53b5d9
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Aug 10, 2023
11be831
remove static env variable expansion
balazsorban44 Aug 10, 2023
160d77d
upgrade Next.js
balazsorban44 Aug 10, 2023
024ba3e
respect `AUTH_URL` and `NEXTAUTH_URL`
balazsorban44 Aug 10, 2023
bf3b483
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Aug 11, 2023
1815cd1
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Aug 12, 2023
82b6f7a
update dev app
balazsorban44 Aug 14, 2023
3852789
implement `signIn` and `signOut` server actions
balazsorban44 Aug 14, 2023
ffd0553
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Aug 14, 2023
5749b09
fix: rm .js from imports (#8669)
juliusmarminge Sep 22, 2023
e36c4c6
feat: update v5 example (#8735)
ThangHuuVu Sep 27, 2023
5648658
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Sep 27, 2023
8aab91b
use server actions
balazsorban44 Sep 27, 2023
ed741bb
update deps
balazsorban44 Sep 27, 2023
c5575f3
tweaks
balazsorban44 Sep 27, 2023
3969246
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Sep 27, 2023
e776ccd
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Sep 27, 2023
b6445e4
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Sep 27, 2023
5984468
fix docs
balazsorban44 Sep 27, 2023
377625f
package.json tweaks
balazsorban44 Sep 27, 2023
7f41a08
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Sep 27, 2023
f127da6
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Sep 27, 2023
36f8e00
bump react types, fix type issues
balazsorban44 Sep 28, 2023
ffc584e
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Sep 28, 2023
289c490
add update action
balazsorban44 Sep 28, 2023
058cb54
bump next to canary
balazsorban44 Sep 28, 2023
908be23
simplify example
balazsorban44 Sep 28, 2023
27bcf0f
fix types and paths
balazsorban44 Sep 28, 2023
3587e16
return null if no session
balazsorban44 Sep 28, 2023
68f7ce1
fix links
balazsorban44 Sep 28, 2023
37865b6
simplify example
balazsorban44 Sep 28, 2023
f2c23db
fix: add getSetCookie to session cookies if supported (#8631)
edenstrom Sep 29, 2023
70a585c
simplify
balazsorban44 Sep 29, 2023
c885ac1
bump typescript
balazsorban44 Sep 29, 2023
7264de5
ignore supabase test
ThangHuuVu Oct 7, 2023
bc36c80
refactor `signIn` and `signOut` methods
balazsorban44 Oct 11, 2023
2304529
fix urls
balazsorban44 Oct 11, 2023
4c69001
support credentials, add docs
balazsorban44 Oct 11, 2023
c8300b6
remove dupicate docs
balazsorban44 Oct 11, 2023
76e382b
docs
balazsorban44 Oct 11, 2023
21555b3
indent
balazsorban44 Oct 11, 2023
dacbe24
handle errors, support auth params
balazsorban44 Oct 12, 2023
caf5cbf
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Oct 23, 2023
a153986
infer provider env vars even if a function form is provided
balazsorban44 Oct 23, 2023
c65ee02
remove redundant useSecureCookies flag setting
balazsorban44 Oct 23, 2023
e68cde9
bump `next`
balazsorban44 Oct 23, 2023
d41e373
simplify Prisma instatation
balazsorban44 Oct 23, 2023
3dd91f8
upgrade migration files
balazsorban44 Oct 23, 2023
b74d3e8
run user's `session` callback if defined, even on server
balazsorban44 Oct 23, 2023
8dbcd25
use `Session` instead of `AuthSession`
balazsorban44 Oct 23, 2023
5fecd19
add server action `update`
balazsorban44 Oct 23, 2023
05243b5
Merge branch 'main' into feat/nextjs-auth
balazsorban44 Oct 23, 2023
80c02bf
add jwt callback to update session
balazsorban44 Oct 23, 2023
73af7ab
fix example
balazsorban44 Oct 23, 2023
1c3584f
remove empty line
balazsorban44 Oct 23, 2023
dcd746c
drop `serverActions: true` flag
balazsorban44 Oct 23, 2023
cfb42ae
bump lock file
balazsorban44 Oct 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/pr-labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ fauna: ["packages/adapter-fauna/**/*"]
firebase: ["packages/adapter-firebase/**/*"]
hasura: ["packages/adapter-hasura/**/*"]
frameworks: ["packages/frameworks-*/**/*"]
legacy: ["packages/next-auth/**/*"]
mikro-orm: ["packages/adapter-mikro-orm/**/*"]
mongodb: ["packages/adapter-mongodb/**/*"]
neo4j: ["packages/adapter-neo4j/**/*"]
next-auth: ["packages/next-auth/**/*"]
pg: ["packages/adapter-pg/**/*"]
playgrounds: ["apps/playgrounds/**/*"]
pouchdb: ["packages/adapter-pouchdb/**/*"]
Expand Down
13 changes: 6 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ dist
.cache-loader
packages/next-auth/providers
packages/next-auth/src/providers/oauth-types.ts
packages/next-auth/client
packages/next-auth/css
packages/next-auth/utils
packages/next-auth/core
packages/next-auth/jwt
packages/next-auth/react
packages/next-auth/next
packages/*/*.js
packages/*/*.d.ts
packages/*/*.d.ts.map
Expand Down Expand Up @@ -90,7 +83,13 @@ packages/core/providers
packages/core/src/lib/pages/styles.ts
docs/docs/reference/core
docs/docs/reference/sveltekit
docs/docs/reference/nextjs

# Next.js
packages/next-auth/lib
packages/next-auth/providers
# copied from @auth/core
packages/next-auth/src/providers

# SvelteKit
packages/frameworks-sveltekit/index.*
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ coverage
dist
packages/**/*.cjs
packages/**/*.js
!packages/*/scripts/*.js

# @auth/core
packages/core/src/providers/oauth-types.ts
Expand Down
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"files.exclude": {
"packages/core/{lib,providers,*.js,*.d.ts,*.d.ts.map}": true,
"packages/next-auth/{client,core,css,jwt,next,providers,react,utils,*.js,*.d.ts}": true
},
"typescript.tsdk": "node_modules/typescript/lib",
"openInGitHub.remote.branch": "main"
}
}
7 changes: 7 additions & 0 deletions apps/dev/nextjs/app/api/protected/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { auth } from "auth"
import { NextResponse } from "next/server"

export const GET = auth(function GET(req) {
if (req.auth) return NextResponse.json(req.auth)
return NextResponse.json({ message: "Not authenticated" }, { status: 401 })
})
15 changes: 15 additions & 0 deletions apps/dev/nextjs/app/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { handlers } from "auth"
const { GET: AuthGET, POST } = handlers
export { POST }

import type { NextRequest } from "next/server"

// Showcasing advanced initialization in Route Handlers
export async function GET(request: NextRequest) {
// Do something with request
const response = await AuthGET(request)
// Do something with response
return response
}

// export const runtime = "edge"
16 changes: 16 additions & 0 deletions apps/dev/nextjs/app/client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use client"

import { signIn, useSession } from "next-auth/react"

export default function Client() {
const { data: session, update, status } = useSession()
return (
<div>
<pre>
{status === "loading" ? "Loading..." : JSON.stringify(session, null, 2)}
</pre>
<button onClick={() => signIn("github")}>Sign in</button>
<button onClick={() => update(`New Name`)}>Update session</button>
</div>
)
}
3 changes: 3 additions & 0 deletions apps/dev/nextjs/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <h1>This page is protected.</h1>
}
58 changes: 51 additions & 7 deletions apps/dev/nextjs/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,56 @@
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
import { auth, signIn, signOut, update } from "auth"
import Footer from "components/footer"
import { Header } from "components/header"
import styles from "components/header.module.css"
import "./styles.css"

export default function RootLayout(props: { children: React.ReactNode }) {
return (
<html>
<head></head>
<body>{children}</body>
<body>
<AppHeader />
<main>{props.children}</main>
<div>
<form
action={async () => {
"use server"
update({ user: { name: "New Name" } })
}}
>
<button>Update name</button>
</form>
</div>
<Footer />
</body>
</html>
)
}

export async function AppHeader() {
const session = await auth()
return (
<Header
session={session}
signIn={
<form
action={async () => {
"use server"
await signIn("github")
}}
>
<button className={styles.buttonPrimary}>Sign in</button>
</form>
}
signOut={
<form
action={async () => {
"use server"
await signOut()
}}
>
<button className={styles.button}>Sign out</button>
</form>
}
/>
)
}
23 changes: 23 additions & 0 deletions apps/dev/nextjs/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { SessionProvider } from "next-auth/react"
import { auth } from "auth"
import Client from "./client"

export default async function Page() {
const session = await auth()
return (
<>
{/*
NOTE: The `auth()` result is not run through the `session` callback, be careful passing down data
to a client component, this will be exposed via the /api/auth/session endpoint
*/}
<SessionProvider session={session} basePath="/auth">
<Client />
</SessionProvider>
<h1>NextAuth.js Example</h1>
<p>
This is an example site to demonstrate how to use{" "}
<a href="https://nextjs.authjs.dev">NextAuth.js</a> for authentication.
</p>
</>
)
}
6 changes: 0 additions & 6 deletions apps/dev/nextjs/app/server-component/page.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ body {
max-width: 680px;
margin: 0 auto;
background: #fff;
color: #333;
color: var(--color-text);
}

li,
Expand Down
52 changes: 52 additions & 0 deletions apps/dev/nextjs/auth.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { NextAuthConfig } from "next-auth"
import Auth0 from "next-auth/providers/auth0"
import Credentials from "next-auth/providers/credentials"
import Facebook from "next-auth/providers/facebook"
import GitHub from "next-auth/providers/github"
import Google from "next-auth/providers/google"
import Twitter from "next-auth/providers/twitter"

declare module "next-auth" {
/**
* Returned by `useSession`, `getSession` and received as a prop on the `SessionProvider` React Context
*/
interface Session {
user: {
/** The user's postal address. */
address: string
} & User
}

interface User {
foo: string
}
}

export default {
debug: false,
providers: [
GitHub({ account() {} }),
Auth0,
Facebook,
Google,
Twitter,
Credentials({
credentials: { password: { label: "Password", type: "password" } },
authorize(c) {
if (c.password !== "password") return null
return {
id: "test",
foo: "bar",
name: "Test User",
email: "test@example.com",
}
},
}),
],
callbacks: {
jwt({ token, trigger, session }) {
if (trigger === "update") token.name = session.user.name
return token
},
},
} satisfies NextAuthConfig
19 changes: 19 additions & 0 deletions apps/dev/nextjs/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import NextAuth from "next-auth"
import Email from "next-auth/providers/email"
import authConfig from "auth.config"
import { PrismaClient } from "@prisma/client"
import { PrismaAdapter } from "@auth/prisma-adapter"

globalThis.prisma ??= new PrismaClient()

// authConfig.providers.push(
// // Start server with `pnpm email`
// // @ts-expect-error
// Email({ server: "smtp://127.0.0.1:1025?tls.rejectUnauthorized=false" })
// )

export const { handlers, auth, signIn, signOut, update } = NextAuth({
// adapter: PrismaAdapter(globalThis.prisma),
session: { strategy: "jwt" },
...authConfig,
})
20 changes: 0 additions & 20 deletions apps/dev/nextjs/components/access-denied.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Link from "next/link"
import styles from "./footer.module.css"
import packageJSON from "package.json"
import packageJSON from "next-auth/package.json"

export default function Footer() {
return (
Expand All @@ -11,7 +11,7 @@ export default function Footer() {
<a href="https://authjs.dev">Documentation</a>
</li>
<li className={styles.navItem}>
<a href="https://www.npmjs.com/package/@auth/core">NPM</a>
<a href="https://www.npmjs.com/package/next-auth">NPM</a>
</li>
<li className={styles.navItem}>
<a href="https://github.com/nextauthjs/next-auth-example">GitHub</a>
Expand Down
Loading
Loading