Next.js Discord

Discord Forum

/server route 404

Answered
Giant panda posted this in #help-forum
Open in Discord
Giant pandaOP
Hello, I started a new nextjs project with nextauth. I got it to the point where signin works after configuring discord and credentials providers, but when I get redirected back from discord or after clicking sign in with credentials, I am redirected to /server, where I get a 404 page not found error.

I tried going to /api/auth/server and there I get a Error: This action with HTTP GET is not supported by NextAuth.js

I'm not sure why is it redirecting to just /server, can I configure this somewhere?

lib/auth.ts
import { NextAuthOptions } from "next-auth";
import DiscordProvider from "next-auth/providers/discord";
import CredentialsProvider from "next-auth/providers/credentials";

export const authOptions: NextAuthOptions = {
  providers: [
    DiscordProvider({
      clientId: process.env.DISCORD_CLIENT_ID,
      clientSecret: process.env.DISCORD_CLIENT_SECRET,
    }),
    CredentialsProvider({
      name: "Sign in",
      credentials: {
        email: {
          label: "Email",
          type: "email",
          placeholder: "test@test.com",
        },
        password: { label: "Password", type: "password" },
      },
      async authorize(credentials) {
        const user = { id: "1", name: "Test", email: "test@test.com" };
        return user;
      },
    }),
  ],
};


app/api/auth/[...nextauth]/route.ts
import NextAuth from "next-auth";
import { authOptions } from "@/lib/auth";

const handler = NextAuth(authOptions);

export { handler as GET, handler as POST };
Answered by French Spaniel
Try specifying something in the callback url for the sign in for creds provider and see what happens
View full answer

9 Replies

Giant pandaOP
Versions:
- next-auth@4.23.1
- next@13.4.19
Giant pandaOP
I noticed that even though the /server page is 404, it still logs me in; if I manually navigate to a page that displays session data, it works; I'm not sure why the /server page is 404.
@French Spaniel https://next-auth.js.org/getting-started/client#specifying-a-callbackurl
Giant pandaOP
So it should take me back to the page where I started signing in.
So it randomly started working about 30 minutes ago and then broke again; keep in mind that I haven't touched the next auth code since then; I was in the css file the entire time.
So I assumed it was a browser or cache issue, but after switching browsers and trying in the Incignito tab, nothing worked.
French Spaniel
Try specifying something in the callback url for the sign in for creds provider and see what happens
Answer
@French Spaniel Try specifying something in the callback url for the sign in for creds provider and see what happens
Giant pandaOP
Okay, thanks for the help. I guess I'll have to manually define the callback url.