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

The CSRF token is not being passed in the body of the request to the Auth method from Auth.js #939

Open
gkettani opened this issue Jan 18, 2025 · 1 comment
Labels

Comments

@gkettani
Copy link

gkettani commented Jan 18, 2025

Which middleware has the bug?

@hono/auth-js

What version of the middleware?

1.0.15

What version of Hono are you using?

4.6.11

What runtime/platform is your app running on? (with version if possible)

Bun

What steps can reproduce the bug?

  1. Create a sample React app using vite
import { signIn } from "@hono/auth-js/react";

function App() {
  return (
    <>
      <Button onClick={() => signIn("google")}>Sign In now</Button>
    </>
  );

}
createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <SessionProvider>
      <App />
    </SessionProvider>
  </StrictMode>
);
  1. Then in the backend, use hono + bun
app.use(
  '*',
  initAuthConfig((c) => ({
    secret: c.env.AUTH_SECRET,
    providers: [
      GoogleProvider({
        clientId: c.env.GOOGLE_CLIENT_ID,
        clientSecret: c.env.GOOGLE_CLIENT_SECRET,
      }),
    ],
    basePath: '/api/auth',
  }))
);

app.use('/api/auth/*', authHandler());

app.use('/api/*', verifyAuth());

What is the expected behavior?

The user should be able to sign in, by clicking the sign in button.

What do you see instead?

The operation fails, returning a CSRF token missing.

Additional information

Upon investigation, the CSRF token is not passed in the body to the Auth method Auth.js

const res = await Auth(reqWithEnvUrl(c.req.raw, ctxEnv.AUTH_URL), config)

Auth.js expects to receive the csrfToken as part of the body on POST requests

@gkettani gkettani reopened this Jan 19, 2025
@yusukebe
Copy link
Member

@gkettani Thank you for the issue.

Hi @divyam234, Can you take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants