小编Lal*_*mar的帖子

使用凭证进行 Next-Auth 登录在 NextJS 中不起作用

我正在将 next-auth 包集成到我的新 Next.js 项目中。我已遵循所有 Next.js 和 next-auth 文档,但无法找到解决方案。

我面临的问题是这样的:我想使用提交到在 Laravel 上运行的 API 服务器的电子邮件和密码登录我的 Next.js 应用程序。提交登录表单时,我正在执行以下功能。

import { signIn } from "next-auth/client";

const loginHandler = async (event) => {
    event.preventDefault();

    const enteredEmail = emailInputRef.current.value;
    const enteredPassword = passwordInputRef.current.value;

    const result = await signIn("credentials", {
        redirect: false,
        email: enteredEmail,
        password: enteredPassword,
    });

    console.log("finished signIn call");
    console.log(result);
};
Run Code Online (Sandbox Code Playgroud)

下面显示的代码在我的pages/api/auth/[...nextauth].js

import axios from "axios";
import NextAuth from "next-auth";
import Providers from "next-auth/providers";

export default NextAuth({
    session: {
        jwt: true,
    },
    providers: [ …
Run Code Online (Sandbox Code Playgroud)

javascript next.js next-auth

16
推荐指数
2
解决办法
4万
查看次数

标签 统计

javascript ×1

next-auth ×1

next.js ×1