Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update Next.js example, bump dependencies
- Loading branch information
1 parent
5081d25
commit 9457593
Showing
9 changed files
with
136 additions
and
117 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
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,40 +1,32 @@ | ||
{ | ||
"name": "next-auth-example", | ||
"version": "0.0.0", | ||
"private": true, | ||
"description": "An example project for NextAuth.js", | ||
"description": "An example project for NextAuth.js with Next.js", | ||
"repository": "https://github.com/nextauthjs/next-auth-example.git", | ||
"bugs": { | ||
"url": "https://github.com/nextauthjs/next-auth/issues" | ||
}, | ||
"homepage": "https://next-auth-example.vercel.app", | ||
"main": "", | ||
"scripts": { | ||
"dev": "next", | ||
"build": "next build", | ||
"start": "next start", | ||
"types": "tsc --noEmit" | ||
"start": "next start" | ||
}, | ||
"author": "Iain Collins <me@iaincollins.com>", | ||
"contributors": [ | ||
"Balázs Orbán <info@balazsorban.com>", | ||
"Nico Domino <yo@ndo.dev>", | ||
"Lluis Agusti <hi@llu.lu>" | ||
], | ||
"license": "ISC", | ||
"dependencies": { | ||
"next": "12.1.7-canary.51", | ||
"next": "latest", | ||
"next-auth": "latest", | ||
"nodemailer": "^6", | ||
"react": "^18", | ||
"react-dom": "^18" | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^17", | ||
"@types/react": "^18", | ||
"@types/react": "^18.0.15", | ||
"typescript": "^4" | ||
}, | ||
"prettier": { | ||
"semi": false | ||
} | ||
} |
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,10 +1,14 @@ | ||
// This is an example of how to read a JSON Web Token from an API route | ||
import { getToken } from "next-auth/jwt" | ||
|
||
import type { NextApiRequest, NextApiResponse } from "next" | ||
|
||
const secret = process.env.NEXTAUTH_SECRET | ||
|
||
export default async (req: NextApiRequest, res: NextApiResponse) => { | ||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
// This is an example of to protect an API route | ||
import { unstable_getServerSession } from "next-auth/next" | ||
import { authOptions } from "../auth/[...nextauth]" | ||
|
||
import type { NextApiRequest, NextApiResponse } from "next" | ||
|
||
export default async (req: NextApiRequest, res: NextApiResponse) => { | ||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
const session = await unstable_getServerSession(req, res, authOptions) | ||
|
||
if (session) { | ||
res.send({ | ||
return res.send({ | ||
content: | ||
"This is protected content. You can access this content because you are signed in.", | ||
}) | ||
} else { | ||
res.send({ | ||
error: | ||
"You must be signed in to view the protected content on this page.", | ||
}) | ||
} | ||
|
||
res.send({ | ||
error: "You must be signed in to view the protected content on this page.", | ||
}) | ||
} |
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,8 +1,13 @@ | ||
// This is an example of how to access a session from an API route | ||
import { getSession } from "next-auth/react" | ||
import { unstable_getServerSession } from "next-auth" | ||
import { authOptions } from "../auth/[...nextauth]" | ||
|
||
import type { NextApiRequest, NextApiResponse } from "next" | ||
|
||
export default async (req: NextApiRequest, res: NextApiResponse) => { | ||
const session = await getSession({ req }) | ||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
const session = await unstable_getServerSession(req, res, authOptions) | ||
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
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.