Skip to content

Commit f62a985

Browse files
docs: clarify getToken and secret
Ref: #4954
1 parent edd6fb5 commit f62a985

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

docs/docs/tutorials/securing-pages-and-api-routes.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ You need to add this to every server rendered page you want to protect. Be aware
6363
```js title="pages/server-side-example.js"
6464
import { unstable_getServerSession } from "next-auth/next"
6565
import { authOptions } from "./api/auth/[...nextauth]"
66-
import {useSession} from "next-auth/react"
66+
import { useSession } from "next-auth/react"
6767

6868
export default function Page() {
6969
const { data: session } = useSession()
@@ -145,10 +145,9 @@ If you are using JSON Web Tokens you can use the `getToken()` helper to access t
145145
// This is an example of how to read a JSON Web Token from an API route
146146
import { getToken } from "next-auth/jwt"
147147

148-
const secret = process.env.SECRET
149-
150148
export default async (req, res) => {
151-
const token = await getToken({ req, secret })
149+
// If you don't have NEXTAUTH_SECRET set, you will have to pass your secret as `secret` to `getToken`
150+
const token = await getToken({ req })
152151
if (token) {
153152
// Signed in
154153
console.log("JSON Web Token", JSON.stringify(token, null, 2))

0 commit comments

Comments
 (0)