Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
kamlendras authored May 6, 2024
1 parent 4f1e22e commit fa7c91b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/api/examples/jwt.js
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))
}
12 changes: 12 additions & 0 deletions app/api/examples/protected.js
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.' })
}
}
7 changes: 7 additions & 0 deletions app/api/examples/session.js
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))
}

0 comments on commit fa7c91b

Please sign in to comment.