get NextAuth Providers server side
Unanswered
Oriental chestnut gall wasp posted this in #help-forum
Oriental chestnut gall waspOP
I'm currently trying to fetch the providers, used in NextAuth V5, in a server component and i get this error message
TypeError: Failed to parse URL from /api/auth/providers, since there is no getProviders function anymore I wonder how I can get the providers except from client components.10 Replies
You define an array of providers
That is passed to next-auth when initializing it
Correct?
Export that array and import it in your server component
Oriental chestnut gall waspOP
export const {
handlers: { GET, POST },
auth,
} = NextAuth({
session: {
strategy: "jwt",
},
providers: [Discord],
adapter: PrismaAdapter(db),
pages: {
signIn: "/auth/signin",
signOut: "/auth/signout",
},
callbacks: {
authorized(params) {
return !!params.auth?.user;
},
jwt: async (data) => {
return data.token;
},
session: async ({ session, user, token }) => {
// @ts-expect-error
session.user.id = token.sub;
return session;
},
},
// @ts-expect-error
}) satisfies NextAuthConfig; my auth.ts looks like this
Oriental chestnut gall waspOP
I want to create a custom signin page as a server component, so I need my providers there.
Had Client components with the GET request to /api/auth/providers before and it worked fine
The solution I provided above should work
Is there something preventing you from doing it?
Oriental chestnut gall waspOP
export const AuthProviders = [Discord];
export const {
handlers: { GET, POST },
auth,
} = NextAuth({
session: {
strategy: "jwt",
},
providers: AuthProviders,
adapter: PrismaAdapter(db),
...AuthProviders is a
[ [Function: Discord] ] now and as I tried so far I can only get the name property from it. But the signin function needs the provider.id