-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f1e22e
commit fa7c91b
Showing
3 changed files
with
28 additions
and
0 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,9 @@ | ||
// This is an example of how to read a JSON Web Token from an API route | ||
import { getToken } from 'next-auth/jwt' | ||
|
||
const secret = process.env.SECRET | ||
|
||
export default async (req, res) => { | ||
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// This is an example of to protect an API route | ||
import { getSession } from 'next-auth/react' | ||
|
||
export default async (req, res) => { | ||
const session = await getSession({ req }) | ||
|
||
if (session) { | ||
res.send({ content: 'This is protected content. You can access this content because you are signed in.' }) | ||
} else { | ||
res.send({ error: 'You must be sign 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// This is an example of how to access a session from an API route | ||
import { getSession } from 'next-auth/react' | ||
|
||
export default async (req, res) => { | ||
const session = await getSession({ req }) | ||
res.send(JSON.stringify(session, null, 2)) | ||
} |