problems with next-auth

I have had problems with next-auth, with discord (or any provider), I downloaded the next authjs demo and it doesn't work either. https://github.com/nextauthjs/next-auth-example
GitHub
GitHub - nextauthjs/next-auth-example: Example showing how to use N...
Example showing how to use NextAuth.js with Next.js - GitHub - nextauthjs/next-auth-example: Example showing how to use NextAuth.js with Next.js
80 Replies
barry
barry•15mo ago
Idk what you want us to do about that, "doesn't work" is not very specific...
Miia
MiiaOP•15mo ago
Well, there is nothing, there is nothing, even with debug active. there is nothing
Miia
MiiaOP•15mo ago
Miia
MiiaOP•15mo ago
I have everything the same as the next-auth example, it does not show any error log.
barry
barry•15mo ago
You didn't set environment variables or? Did you do any of the steps it says to
Miia
MiiaOP•15mo ago
yes NEXTAUTH_SECRET=xxxx* NEXTAUTH_URL=http://localhost:3000 I have everything, 100% the same
barry
barry•15mo ago
You need more than that
Miia
MiiaOP•15mo ago
what do you need? can I send you a picture of something?
barry
barry•15mo ago
No, you need more environment variables than that
Miia
MiiaOP•15mo ago
i also have the [nextauth].ts if you mean that, the options and parameters and the sessioncontext sure? It says here that only these two, what else?
barry
barry•15mo ago
No it doesn't Lemme quote it
Add details for one or more providers (e.g. Google, Twitter, GitHub, Email, etc).
Miia
MiiaOP•15mo ago
ISCORD_CLIENT_ID=1146254896799158284 DISCORD_CLIENT_SECRET=xxx* I also have this.
Miia
MiiaOP•15mo ago
No description
barry
barry•15mo ago
And you pushed your prisma schema to your db
Miia
MiiaOP•15mo ago
yes
Miia
MiiaOP•15mo ago
No description
Miia
MiiaOP•15mo ago
ignore other tables, they are not used at all. the db is from the next-auth example
barry
barry•15mo ago
And you setup a callback url in discord
Miia
MiiaOP•15mo ago
yes
barry
barry•15mo ago
And there is no errors in either of your consoles when clicking the login button
Miia
MiiaOP•15mo ago
No description
Miia
MiiaOP•15mo ago
you have clicked" but no error is displayed. none
barry
barry•15mo ago
not even on the server console?
Miia
MiiaOP•15mo ago
nup I'm going crazy I don't understand what's going on.
barry
barry•15mo ago
node version?
Miia
MiiaOP•15mo ago
18
barry
barry•15mo ago
show login component
Miia
MiiaOP•15mo ago
No description
barry
barry•15mo ago
What if you change this to https
Miia
MiiaOP•15mo ago
I also tried with callbackUrl, parameters etc and none of them worked. it is localhost. it should not matter. 1s https://localhost:3000/api/auth/callback/discord this?
barry
barry•15mo ago
yh
Miia
MiiaOP•15mo ago
hm nu same xD
barry
barry•15mo ago
ok browser problem i think try incognito or other browser
Miia
MiiaOP•15mo ago
I did it too, it doesn't work on any of them ;D chrome, brave, firefox, etc /auth/signin?csrf=true csrf=true
barry
barry•15mo ago
wtf what if you remove the void here
Miia
MiiaOP•15mo ago
1s
Miia
MiiaOP•15mo ago
No description
Miia
MiiaOP•15mo ago
same
Miia
MiiaOP•15mo ago
No description
Miia
MiiaOP•15mo ago
same
barry
barry•15mo ago
yeah ignore it what about when it runs
Miia
MiiaOP•15mo ago
yes yes, it doesn't work, it's the same xD
barry
barry•15mo ago
what if you have a button
Miia
MiiaOP•15mo ago
nothing the same as above 1s
barry
barry•15mo ago
no shadcn just normal button
Miia
MiiaOP•15mo ago
I don't use shadcn, but will put it native 1s nothing same
Miia
MiiaOP•15mo ago
No description
barry
barry•15mo ago
what if you call signIn("discord") literally just in the page
Miia
MiiaOP•15mo ago
No description
Miia
MiiaOP•15mo ago
in fact, it doesn't work here either ;D okay 1s useEffect?
barry
barry•15mo ago
nono just in page it will redirect you anyways
Miia
MiiaOP•15mo ago
No description
Miia
MiiaOP•15mo ago
nothing
barry
barry•15mo ago
it's a client component right no errors anywhere?
Miia
MiiaOP•15mo ago
I use pages, so I shouldn't. 1s "use client";
barry
barry•15mo ago
use client is not for pages
Miia
MiiaOP•15mo ago
No description
Miia
MiiaOP•15mo ago
same the same thing happens nup
barry
barry•15mo ago
show your next auth config again but the whole thing imports everything
Miia
MiiaOP•15mo ago
1s
barry
barry•15mo ago
1 last idea in my head lol
Miia
MiiaOP•15mo ago
No description
Miia
MiiaOP•15mo ago
s 1s*
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import { type UserRole } from "@prisma/client";
import { type GetServerSidePropsContext } from "next";
import {
getServerSession,
type DefaultSession,
type NextAuthOptions,
} from "next-auth";
import DiscordProvider from "next-auth/providers/discord";

import { env } from "~/env.mjs";
import { prisma } from "~/server/db";

/**
* Module augmentation for `next-auth` types. Allows us to add custom properties to the `session`
* object and keep type safety.
*
* @see https://next-auth.js.org/getting-started/typescript#module-augmentation
*/
declare module "next-auth" {
interface Session extends DefaultSession {
user: DefaultSession["user"] & {
id: string;
role: UserRole;
};
}

interface User {
role: UserRole;
}
}

/**
* Options for NextAuth.js used to configure adapters, providers, callbacks, etc.
*
* @see https://next-auth.js.org/configuration/options
*/

export const authOptions: NextAuthOptions = {
callbacks: {
session: ({ session, user }) => ({
...session,
user: {
...session.user,
role: user.role,
id: user.id,
},
})
},
providers: [
DiscordProvider({
clientId: env.DISCORD_CLIENT_ID,
clientSecret: env.DISCORD_CLIENT_SECRET,
}),
/**
* ...add more providers here.
*
* Most other providers require a bit more work than the Discord provider. For example, the
* GitHub provider requires you to add the `refresh_token_expires_in` field to the Account
* model. Refer to the NextAuth.js docs for the provider you want to use. Example:
*
* @see https://next-auth.js.org/providers/github
*/
],
adapter: PrismaAdapter(prisma),

debug:true,
};

/**
* Wrapper for `getServerSession` so that you don't need to import the `authOptions` in every file.
*
* @see https://next-auth.js.org/configuration/nextjs
*/
export const getServerAuthSession = (ctx: {
req: GetServerSidePropsContext["req"];
res: GetServerSidePropsContext["res"];
}) => {
return getServerSession(ctx.req, ctx.res, authOptions);
};
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import { type UserRole } from "@prisma/client";
import { type GetServerSidePropsContext } from "next";
import {
getServerSession,
type DefaultSession,
type NextAuthOptions,
} from "next-auth";
import DiscordProvider from "next-auth/providers/discord";

import { env } from "~/env.mjs";
import { prisma } from "~/server/db";

/**
* Module augmentation for `next-auth` types. Allows us to add custom properties to the `session`
* object and keep type safety.
*
* @see https://next-auth.js.org/getting-started/typescript#module-augmentation
*/
declare module "next-auth" {
interface Session extends DefaultSession {
user: DefaultSession["user"] & {
id: string;
role: UserRole;
};
}

interface User {
role: UserRole;
}
}

/**
* Options for NextAuth.js used to configure adapters, providers, callbacks, etc.
*
* @see https://next-auth.js.org/configuration/options
*/

export const authOptions: NextAuthOptions = {
callbacks: {
session: ({ session, user }) => ({
...session,
user: {
...session.user,
role: user.role,
id: user.id,
},
})
},
providers: [
DiscordProvider({
clientId: env.DISCORD_CLIENT_ID,
clientSecret: env.DISCORD_CLIENT_SECRET,
}),
/**
* ...add more providers here.
*
* Most other providers require a bit more work than the Discord provider. For example, the
* GitHub provider requires you to add the `refresh_token_expires_in` field to the Account
* model. Refer to the NextAuth.js docs for the provider you want to use. Example:
*
* @see https://next-auth.js.org/providers/github
*/
],
adapter: PrismaAdapter(prisma),

debug:true,
};

/**
* Wrapper for `getServerSession` so that you don't need to import the `authOptions` in every file.
*
* @see https://next-auth.js.org/configuration/nextjs
*/
export const getServerAuthSession = (ctx: {
req: GetServerSidePropsContext["req"];
res: GetServerSidePropsContext["res"];
}) => {
return getServerSession(ctx.req, ctx.res, authOptions);
};
it doesn't work either, if I remove the role, in case you had any doubts xD
barry
barry•15mo ago
what if you ditch env, and just copy pasta the keys in
Miia
MiiaOP•15mo ago
hm 1s
Miia
MiiaOP•15mo ago
No description
Miia
MiiaOP•15mo ago
nothing same result
barry
barry•15mo ago
idk anymore lol
Miia
MiiaOP•15mo ago
No description
barry
barry•15mo ago
i gotta go take the fucking bus, maybe share repo maybe someone can clone it locally and see if it works for them and report back
Miia
MiiaOP•15mo ago
"next": "^13.4.5", "next-auth": "^4.23.0",
Miia
MiiaOP•15mo ago
No description
Miia
MiiaOP•15mo ago
using an https domain does not work either.
Miia
MiiaOP•15mo ago
No description
BarisP
BarisP•15mo ago
Check your db, if you have any user and accounts, delete everything and try once more. Try different browsers and double check everyting
NotRoman
NotRoman•15mo ago
Clear your cookies as well
Miia
MiiaOP•15mo ago
I have tried everything and nothing works, even downloading the t3 template does not work. ;D
j6rms
j6rms•14mo ago
@miia.dev did you happen to find a solution? I've been struggling with the same issue for quite a while It seems completely random. I've managed to get the signin to work for a while but even then it will not work if I try to open a parallel session in incognito mode We discussed it here https://discord.com/channels/966627436387266600/1140674141872197662 but found no clues Hmm, found this thread https://discord.com/channels/966627436387266600/1146902566848970882 and upgrading to latest Node version seemed to work For now... 😄
Miia
MiiaOP•14mo ago
@j6rms It ends up fixing it, deleting all dependencies and running an npm upgrade (absolute), basically update all libraries, existing in the project to the latest possible no matter if there are errors or incompatibility, it seems to be a node+nextjs problem and a weird interaction with some method.
Want results from more Discord servers?
Add your server