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•10mo ago
Idk what you want us to do about that, "doesn't work" is not very specific...
Miia
Miia•10mo ago
Well, there is nothing, there is nothing, even with debug active. there is nothing
Miia
Miia•10mo ago
Miia
Miia•10mo ago
I have everything the same as the next-auth example, it does not show any error log.
barry
barry•10mo ago
You didn't set environment variables or? Did you do any of the steps it says to
Miia
Miia•10mo ago
yes NEXTAUTH_SECRET=xxxx* NEXTAUTH_URL=http://localhost:3000 I have everything, 100% the same
barry
barry•10mo ago
You need more than that
Miia
Miia•10mo ago
what do you need? can I send you a picture of something?
barry
barry•10mo ago
No, you need more environment variables than that
Miia
Miia•10mo 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•10mo ago
No it doesn't Lemme quote it
Add details for one or more providers (e.g. Google, Twitter, GitHub, Email, etc).
Miia
Miia•10mo ago
ISCORD_CLIENT_ID=1146254896799158284 DISCORD_CLIENT_SECRET=xxx* I also have this.
Miia
Miia•10mo ago
No description
barry
barry•10mo ago
And you pushed your prisma schema to your db
Miia
Miia•10mo ago
yes
Miia
Miia•10mo ago
No description
Miia
Miia•10mo ago
ignore other tables, they are not used at all. the db is from the next-auth example
barry
barry•10mo ago
And you setup a callback url in discord
Miia
Miia•10mo ago
yes
barry
barry•10mo ago
And there is no errors in either of your consoles when clicking the login button
Miia
Miia•10mo ago
No description
Miia
Miia•10mo ago
you have clicked" but no error is displayed. none
barry
barry•10mo ago
not even on the server console?
Miia
Miia•10mo ago
nup I'm going crazy I don't understand what's going on.
barry
barry•10mo ago
node version?
Miia
Miia•10mo ago
18
barry
barry•10mo ago
show login component
Miia
Miia•10mo ago
No description
barry
barry•10mo ago
What if you change this to https
Miia
Miia•10mo 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•10mo ago
yh
Miia
Miia•10mo ago
hm nu same xD
barry
barry•10mo ago
ok browser problem i think try incognito or other browser
Miia
Miia•10mo 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•10mo ago
wtf what if you remove the void here
Miia
Miia•10mo ago
1s
Miia
Miia•10mo ago
No description
Miia
Miia•10mo ago
same
Miia
Miia•10mo ago
No description
Miia
Miia•10mo ago
same
barry
barry•10mo ago
yeah ignore it what about when it runs
Miia
Miia•10mo ago
yes yes, it doesn't work, it's the same xD
barry
barry•10mo ago
what if you have a button
Miia
Miia•10mo ago
nothing the same as above 1s
barry
barry•10mo ago
no shadcn just normal button
Miia
Miia•10mo ago
I don't use shadcn, but will put it native 1s nothing same
Miia
Miia•10mo ago
No description
barry
barry•10mo ago
what if you call signIn("discord") literally just in the page
Miia
Miia•10mo ago
No description
Miia
Miia•10mo ago
in fact, it doesn't work here either ;D okay 1s useEffect?
barry
barry•10mo ago
nono just in page it will redirect you anyways
Miia
Miia•10mo ago
No description
Miia
Miia•10mo ago
nothing
barry
barry•10mo ago
it's a client component right no errors anywhere?
Miia
Miia•10mo ago
I use pages, so I shouldn't. 1s "use client";
barry
barry•10mo ago
use client is not for pages
Miia
Miia•10mo ago
No description
Miia
Miia•10mo ago
same the same thing happens nup
barry
barry•10mo ago
show your next auth config again but the whole thing imports everything
Miia
Miia•10mo ago
1s
barry
barry•10mo ago
1 last idea in my head lol
Miia
Miia•10mo ago
No description
Miia
Miia•10mo 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•10mo ago
what if you ditch env, and just copy pasta the keys in
Miia
Miia•10mo ago
hm 1s
Miia
Miia•10mo ago
No description
Miia
Miia•10mo ago
nothing same result
barry
barry•10mo ago
idk anymore lol
Miia
Miia•10mo ago
No description
barry
barry•10mo 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
Miia•10mo ago
"next": "^13.4.5", "next-auth": "^4.23.0",
Miia
Miia•10mo ago
No description
Miia
Miia•10mo ago
using an https domain does not work either.
Miia
Miia•10mo ago
No description
BarisP
BarisP•10mo 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•10mo ago
Clear your cookies as well
Miia
Miia•10mo ago
I have tried everything and nothing works, even downloading the t3 template does not work. ;D
j6rms
j6rms•9mo 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
Miia•9mo 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.