Next Auth Spotify Provider
Unanswered
Saltwater Crocodile posted this in #help-forum
Saltwater CrocodileOP
I'm trying to connect my app with spotif. I'm using the ebta of next-auth 5. When I click on accept in the login it throws an error of invalid redirect URI. Inside spotify dashboards I added this uri http://127.0.0.1:3000/api/auth/callback/spotify since localhost is forbidden. Anyone has the same error or know how to fix it? This is the config I'm using for the providers.
import NextAuth, { Session } from 'next-auth';
import { JWT } from 'next-auth/jwt';
import { Provider } from 'next-auth/providers';
import Spotify from 'next-auth/providers/spotify';
export interface ISession extends Session {
accessToken?: string;
}
export interface IJWT extends JWT {
accessToken?: string;
}
const providers: Provider[] = [
Spotify({
clientId: process.env.SPOTIFY_CLIENT_ID,
clientSecret: process.env.SPOTIFY_CLIENT_SECRET,
authorization: {
url: 'https://accounts.spotify.com/authorize',
params: {
scope: 'user-read-email user-read-private',
},
},
}),
];
export const { handlers, auth, signIn, signOut } = NextAuth({
providers,
callbacks: {
jwt: async ({ token, account }) => {
if (account?.provider === 'spotify') {
return { ...token, accessToken: account.access_token };
}
return token;
},
async session({ session, token }: { session: ISession; token: IJWT }) {
session.accessToken = token.accessToken;
return session;
},
},
});