#How to get a bearer token from nextauth

6 messages · Page 1 of 1 (latest)

median pivot
#

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

// 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: A4280000error0A00010B: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'
}

dusk umbraBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

median pivot
#

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

rocky wagon
#

bro in line second name the function getToken to handler

#

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

median pivot
#

solution found, was fetiching to https