How to request in server side for Credentials Provider in next-auth

Viewed 356

I'm having trouble figuring out how to request in backend for a credentials provider login.

I created 2 Credential Provider with different ids(credentials and token)

I attempted the following(per https://next-auth.js.org/getting-started/rest-api#post-apiauthsigninprovider)

POST /api/auth/signin/credentials
POST /api/auth/signin/token

But it seems to return 404 Not Found

I also tried utilizing the route used by the default login form

POST /api/auth/callback/credentials
POST /api/auth/callback/token

But also a 404(also included a csrfToken)

Here is a code snippet

import { HOME_PAGE, LOGIN_PAGE } from '@app/constants/routes';
import { backendApi } from '@app/lib/api';
import { getCsrfToken, signIn } from 'next-auth/react';

export default async function handler(req, res) {
  try {
    const { accessToken} = req.query;
    const csrfToken = await getCsrfToken();

    await backendApi.post('/auth/signin/token', {
      csrfToken,
      accessToken,
    });

    res.redirect(307, HOME_PAGE);
  } catch (error) {
    res.redirect(307, LOGIN_PAGE);
  }
}
0 Answers
Related