Next.js Discord

Discord Forum

Next auth link social accounts?

Unanswered
Red-footed Booby posted this in #help-forum
Open in Discord
Avatar
Red-footed BoobyOP
I have a next js app setup with next-auth@beta with credentials. I want to add a feature to connect your account on my website to your spotify account. That should basically do what next auth does with spotify but instead of storing the refresh token and access token in the session/jwt, it should store them in the database. How do I do this? i tried using both providers, but when I connect to spotify, it just replaces the credentials session with a spotify session/jwt

2 Replies

Avatar
Red-footed BoobyOP
i tried just redirecting the user to https://accounts.spotify.com/authorize?... with a redirect uri to this api route: https://pastes.dev/6lGplkODyH
but I keep getting this error even though the refresh token is correct:
Error response: { error: 'invalid_grant', error_description: 'Invalid refresh token' }
Error fetching access token: Error: Failed to fetch access token: Bad Request
    at getSpotifyAccessToken (file://C%3A/Users/adria/Desktop/dev/typescript/web/next-auth-test/app/api/spotify/%5B...callback%5D/route.ts:89:9)
    at async GET (file://C%3A/Users/adria/Desktop/dev/typescript/web/next-auth-test/app/api/spotify/%5B...callback%5D/route.ts:26:21)
  87 |                  const errorResponse = await response.json();
  88 |                  console.error("Error response:", errorResponse);
> 89 |                  throw new Error(`Failed to fetch access token: ${response.statusText}`);
     |                       ^
  90 |          }
  91 |
  92 |          const data: SpotifyTokenResponse = await response.json();
 ⨯ Error: Failed to refresh Spotify access token
    at getSpotifyAccessToken (file://C%3A/Users/adria/Desktop/dev/typescript/web/next-auth-test/app/api/spotify/%5B...callback%5D/route.ts:97:8)
Avatar
Red-footed BoobyOP
Could someone please help me I think I might be going insane because of this