-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: bump nextjs to 11 * feat: migrate to v4.0.0-next.20 * fix: config comments * fix: add nodemailer as manual dependency * feat: add ndom91 as contributor 😁 * fix: provider import * feat: update next-auth * fix: add package-lock * feat: update next-auth to v4-beta.1 * fix: remove carrot * feat: upgrade to beta.2 * fix: filename typo * feat: add Next.js 12 Middleware example page * chore: simplify Middleware * chore: revert * chore(deps): ugprade `next-auth` * chore: change url check * chore: add logs, refactor middleware * fix: use new theme option * Image url value must be quoted within a string template (#46) * chore: remove lock file * chore: update [email protected] * fix: exact version * Update _middleware.js * fix: comment out email adapter * feat: [email protected] * fix: cleanup options * fix: rm sqlite3 Co-authored-by: Balázs Orbán <[email protected]> Co-authored-by: Shawn Goulet <[email protected]>
- Loading branch information
1 parent
ddd9389
commit b42c128
Showing
13 changed files
with
147 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# https://docs.github.com/en/github/administering-a-repository/displaying-a-sponsor-button-in-your-repository | ||
|
||
open_collective: nextauth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,14 +16,15 @@ | |
}, | ||
"author": "Iain Collins <[email protected]>", | ||
"contributors": [ | ||
"Balázs Orbán <[email protected]>" | ||
"Balázs Orbán <[email protected]>", | ||
"Nico Domino <[email protected]>" | ||
], | ||
"license": "ISC", | ||
"dependencies": { | ||
"next": "^11.0.0", | ||
"next-auth": "latest", | ||
"next": "^12.0.1", | ||
"next-auth": "^4.0.1", | ||
"nodemailer": "^6.6.3", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"sqlite3": "^5.0.2" | ||
"react-dom": "^17.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
import { Provider } from 'next-auth/client' | ||
import { SessionProvider } from 'next-auth/react' | ||
import './styles.css' | ||
|
||
// Use the <Provider> to improve performance and allow components that call | ||
// Use of the <SessionProvider> is now mandatory to allow components that call | ||
// `useSession()` anywhere in your application to access the `session` object. | ||
export default function App ({ Component, pageProps }) { | ||
return ( | ||
<Provider | ||
<SessionProvider | ||
// Provider options are not required but can be useful in situations where | ||
// you have a short session maxAge time. Shown here with default values. | ||
options={{ | ||
// Client Max Age controls how often the useSession in the client should | ||
// Stale Time controls how often the useSession in the client should | ||
// contact the server to sync the session state. Value in seconds. | ||
// e.g. | ||
// * 0 - Disabled (always use cache value) | ||
// * 60 - Sync session state with server if it's older than 60 seconds | ||
clientMaxAge: 0, | ||
// Keep Alive tells windows / tabs that are signed in to keep sending | ||
staleTime: 0, | ||
// Refetch Interval tells windows / tabs that are signed in to keep sending | ||
// a keep alive request (which extends the current session expiry) to | ||
// prevent sessions in open windows from expiring. Value in seconds. | ||
// | ||
// Note: If a session has expired when keep alive is triggered, all open | ||
// windows / tabs will be updated to reflect the user is signed out. | ||
keepAlive: 0 | ||
refetchInterval: 0 | ||
}} | ||
session={pageProps.session} > | ||
<Component {...pageProps} /> | ||
</Provider> | ||
</SessionProvider> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { getToken } from "next-auth/jwt" | ||
import { NextResponse } from "next/server" | ||
|
||
/** @param {import("next/server").NextRequest} req */ | ||
export async function middleware(req) { | ||
if (req.nextUrl.pathname === "/middleware-protected") { | ||
const session = await getToken({ req, secret: process.env.SECRET }) | ||
// You could also check for any property on the session object, | ||
// like role === "admin" or name === "John Doe", etc. | ||
if (!session) return NextResponse.redirect("/api/auth/signin") | ||
// If user is authenticated, continue. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
// This is an example of how to read a JSON Web Token from an API route | ||
import jwt from 'next-auth/jwt' | ||
import { getToken } from 'next-auth/jwt' | ||
|
||
const secret = process.env.SECRET | ||
|
||
export default async (req, res) => { | ||
const token = await jwt.getToken({ req, secret }) | ||
const token = await getToken({ req, secret }) | ||
res.send(JSON.stringify(token, null, 2)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// This is an example of how to access a session from an API route | ||
import { getSession } from 'next-auth/client' | ||
import { getSession } from 'next-auth/react' | ||
|
||
export default async (req, res) => { | ||
const session = await getSession({ req }) | ||
res.send(JSON.stringify(session, null, 2)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Layout from "../components/layout" | ||
|
||
export default function Page() { | ||
return ( | ||
<Layout> | ||
<h1>Page protected by Middleware</h1> | ||
</Layout> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
b42c128
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
next-auth-example – ./
next-auth-example-seven.vercel.app
next-auth-example.vercel.app
next-auth-example-git-main-nextauthjs.vercel.app
next-auth-example-nextauthjs.vercel.app