Replies: 1 comment 2 replies
-
You won't have access to the token until the user is logged in. There's no need to store it in the session, as for your use case there's no need to expose it client-side (which anyway it's insecure). So having just... callbacks: {
jwt: ({token, account })=> {
if (account?.access_token) {
token.accessToken = account.acess_token;
}
return token;
}, and then in your API route doing: import { getToken } from 'next-auth/jwt'
export default async function (req, res) {
const token = await getToken({ req })
// this is just pseudo-code, refer to the actual Google API docs...
return fetch('https://api.google.com/me', {
headers: {
'Content-Type': 'application/json',
Authorization: `token ${token?.accessToken}`
}
} should suffice 👍🏽 |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Question 💬
How to get access_token from next_auth to use it with googleapis,
lets say i am creating a crud app that store the data in google drive, I am using nextjs and next-auth for OAuth implementation for google. i found this https://blog.srij.dev/nextauth-google-access-token so i implemented it. but it logs undefined. and
account
andaccess_token
don't have values, the params object that we receive in the callback only has a token key. which doesnt contain access_token instead it containssub,iat,exp,jti
How to reproduce ☕️
just create a nextjs template project and add this to
src/pages/api/auth/[...nextauth].ts
also get a google_id ,google secret from gcp,enable google drive apis add it in .env file.Contributing 🙌🏽
No, I am afraid I cannot help regarding this
Beta Was this translation helpful? Give feedback.
All reactions