How to get a bearer token from nextauth
Answered
Japanese jack mackerel posted this in #help-forum
Japanese jack mackerelOP
I know theres getToken which should get me the token i just dont understand how to call it. i tried doing a get-token.js
and then in my signed in page
however this got me an error
Cause: [Error: A4280000
0A00010B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:355:
] {
library: 'SSL routines',
reason: 'wrong version number',
code: 'ERR_SSL_WRONG_VERSION_NUMBER'
}
// This is an example of how to read a JSON Web Token from an API route
import { getToken } from "next-auth/jwt"
export default async function getToken(req, res) {
// If you don't have NEXTAUTH_SECRET set, you will have to pass your secret as `secret` to `getToken`
const token = await getToken({ req })
if (token) {
// Signed in
console.log("JSON Web Token", JSON.stringify(token, null, 2))
} else {
// Not Signed in
res.status(401)
}
res.end()
} and then in my signed in page
if (session && session.user){
const response = await fetch(`https://localhost:3000/api/get-token`)
console.log(response)
}however this got me an error
Cause: [Error: A4280000
0A00010B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:355:] {
library: 'SSL routines',
reason: 'wrong version number',
code: 'ERR_SSL_WRONG_VERSION_NUMBER'
}
4 Replies
Japanese jack mackerelOP
like the documentation shows how to set up the hadnler but doesnt show how to call the handler and however im calling it gives the above error
Russian Blue
bro in line second name the function getToken to handler
Russian Blue
i think this gonna solve the problem because you give the declare the function in second line . and then calling the function in next line this arise a conflict
Japanese jack mackerelOP
solution found, was fetiching to https
Answer