Setting up JWT with NextAuth has been a bit of a challenge for me. I've been scouring GitHub posts and doing research, but haven't found much help. It seems like there's an error occurring when NextAuth tries to decode the JWT payload. All I want is to get a string of numbers from Twitch upon signing in so that I can use it in an API call to Twitch.
I'm new to JWT and NextAuth, so I'm still learning!
If anyone could offer some assistance, that would be greatly appreciated!
// console errors
unhandledRejection: TypeError: Cannot read properties of undefined (reading 'next-auth.session-token')
-
error - Error: Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead.
-
TypeError: getCurves is not a function
-
Check out the github repo for the entire project here.
If you're encountering any issues, feel free to refer to the nextjs error page https://i.sstatic.net/l73ZN.png.
//[...nextauth].js
import NextAuth from "next-auth"
import Providers from "next-auth/providers"
export default NextAuth({
providers: [
Providers.Twitch({
clientId: process.env.TWITCH_CLIENT_ID,
clientSecret: process.env.TWITCH_CLIENT_SECRET,
}),
Providers.Spotify({
clientId: process.env.SPOTIFY_CLIENT_ID,
clientSecret: process.env.SPOTIFY_CLIENT_SECRET
}),
],
secret: process.env.SECRET,
session: {
jwt: true,
},
// https://next-auth.js.org/configuration/options#jwt
jwt: {
secret: process.env.SECRET,
},
callbacks: {
async signIn(user, account, profile) { return true },
async session(session, user) { return session },
async jwt(token, user, account, profile, isNewUser) {
token.accessToken = account.access_token;
return token
}
},
theme: 'light',
debug: true,
})
//test.js - trying to decode and use the data inside the web token
import { getToken } from 'next-auth/jwt'
const secret = process.env.SECRET
const test = (req, res) => {
const token = getToken({req, secret});
return (
<div>
<a>{token.sub}</a> // Should show the users id returned from Twitch
</div>
)
}
export default test