Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect to 404 "/api/auth/callback/github?code=" after authentication #12519

Closed
Mordai opened this issue Jan 17, 2025 · 3 comments
Closed

Redirect to 404 "/api/auth/callback/github?code=" after authentication #12519

Mordai opened this issue Jan 17, 2025 · 3 comments
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@Mordai
Copy link

Mordai commented Jan 17, 2025

Environment

  System:
    OS: Linux 6.6 Manjaro Linux
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700K
    Memory: 25.21 GB / 31.11 GB
    Container: Yes
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 23.3.0 - /usr/bin/node
    npm: 11.0.0 - /usr/bin/npm
  npmPackages:
    next: 15.1.4 => 15.1.4 
    next-auth: ^5.0.0-beta.25 => 5.0.0-beta.25 
    react: ^19.0.0 => 19.0.0 

Reproduction URL

https://github.com/Mordai/yt-directory

Describe the issue

When signing in with the GitHub provider using Auth.js (next-auth), after the OAuth flow completes, the user is redirected to http://localhost:3000/api/auth/callback/github?code=CODE (I got a 404 error page there) and not to the default root page (/).

How to reproduce

  1. Set up a Next.js app with the following dependencies:
next: 15.1.4
next-auth: 5.0.0-beta.25
react: 19.0.0
  1. Configure Auth.js with the GitHub provider (in auth.ts file):
import NextAuth from "next-auth";
import GitHub from "next-auth/providers/github";

export const { handlers, signIn, signOut, auth } = NextAuth({
  providers: [GitHub],
});
  1. Create Auth.js App Router files.
    Create a route.ts file in app/api/auth/[...nextauth] folder with the content:
import { handlers } from "@/auth"; // Referring to the auth.ts
export const { GET, POST } = handlers;
  1. Configure a GitHub OAuth App.
    My .env.local file:
AUTH_SECRET=<my secret> # Added by `npx auth`.
AUTH_GITHUB_ID=<my GitHub ID>
AUTH_GITHUB_SECRET=<my GitHub secret>
  1. Call the signIn function on a page:
<form
  action={async () => {
    "use server";
    await signIn("github");
  }}>
  <button type="submit">Sign in</button>
</form>
  1. Sign in with GitHub.
    Observe the redirection sequence:
    After a successfull authentication, you'll be redirected to http://localhost:3000/api/auth/callback/github?code=CODE and see a 404 page.

Expected behavior

After signing in, the user should be redirected back to the app (root), as no custom redirects/middlewares were defined.

@Mordai Mordai added bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Jan 17, 2025
@JayWebtech
Copy link

Try building your project let's see if it will build successfully

@Mordai
Copy link
Author

Mordai commented Jan 18, 2025

Yeah, I tried it (it builds without any errors/warnings), but the same behaviour after running the built application: redirect to a 404 [...]/callback URL.

@Mordai Mordai changed the title Redirect to 404 "/api/auth/callback/github?code=" after authorization Redirect to 404 "/api/auth/callback/github?code=" after authentication Jan 19, 2025
@Mordai
Copy link
Author

Mordai commented Jan 26, 2025

Solved.
I had whitespace in my path :)

@Mordai Mordai closed this as completed Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests

2 participants