我正在尝试使用 Next-Auth 向我的 Next.js 项目添加身份验证,但是500 internal server error
在提交凭据 ( http://localhost:3000/api/auth/error?error=Configuration
) 后我被卡住了。
我认为这可能与在 http://localhost:3000 上运行有关,但我不确定。谁能看到我做错了什么?
pages/api/auth/[...nextauth].js
import NextAuth from 'next-auth';
import Providers from 'next-auth/providers';
const options = {
site: 'http://localhost:3000',
providers: [
Providers.Credentials({
name: 'Credentials',
credentials: {
username: { label: 'Username', type: 'text', placeholder: 'jsmith' },
password: { label: 'Password', type: 'password' },
},
authorize: async (credentials) => {
consol.log('credentials', credentials);
const user = { id: 1, name: 'J Smith', email: 'jsmith@example.com' };
if (user) {
return Promise.resolve(user);
} else {
return Promise.resolve(null);
}
},
}),
],
database: process.env.MONGO_URI,
};
export default (req, res) => NextAuth(req, res, options);
页面/index.js
import { useSession } from 'next-auth/client';
export default function Home() {
const [session, loading] = useSession();
console.log('session', session);
return (
<div className="container">
<main>
{session && <p>Signed in as {session.user.email}</p>}
{!session && (
<p>
<a href="/api/auth/signin">Sign in</a>
</p>
)}
</main>
</div>
);
}
页面/_app.js
import { Provider } from 'next-auth/client';
import '../styles.css';
export default ({ Component, pageProps }) => {
const { session } = pageProps;
return (
<Provider options={{ site: process.env.SITE }} session={session}>
<Component {...pageProps} />
</Provider>
);
};
next.config.js
module.exports = {
env: {
MONGO_URI: '...',
SITE: 'http://localhost:3000',
},
};
任何帮助将非常感激。