下一步验证google登录下载页面而不是导航



我使用nextjs 13(与应用程序目录beta启用)以及下一个身份验证。有时当试图登录谷歌而不是重定向它只是试图下载页面

下面是下一个验证初始化的auth选项示例

import GoogleProvider from "next-auth/providers/google";
import { NextAuthOptions } from "next-auth";
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import { database } from "@/lib/database";
export const authOptions: NextAuthOptions = {
// Configure one or more authentication providers
adapter: PrismaAdapter(database),
session: {
strategy: "jwt",
},
pages: {
signIn: "/login",
},
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET
}),
// ...
],
callbacks: {
async session({ token, session }) {
if (token) {
session.user.id = token.id;
session.user.name = token.name;
session.user.email = token.email;
session.user.image = token.picture;
session.user.status = token.status as string;
}
return session;
},
async jwt({ token, user }) {
const dbUser = await database.user.findFirst({
where: {
email: token.email,
},
});
if (!dbUser) {
token.id = user.id;
return token;
}
return {
id: dbUser.id,
name: dbUser.name,
email: dbUser.email,
picture: dbUser.image,
status: dbUser.status,
};
},
},
};

相关前端代码:

import { signIn, getProviders } from "next-auth/react";
//....
<AuthButton
onClick={() => signIn("google", {})}
>
<FcGoogle size={20} /> Log in with Google
</AuthButton>

它下载的文件看起来像这样

J0:[[["",{"children":["(auth)",{"children":["login",{"children":["",{}]}]}]},null,null,true],"@1",[["$","title",null,{"children":"Storiway - The right way to tell your story"}],["$","meta",null,{"content":"width=device-width, initial-scale=1","name":"viewport"}],["$","meta",null,{"name":"description","content":"Storiway provides an easy to use way to tell customers the stories of your brand."}],["$","link",null,{"rel":"icon","href":"/favicon.ico"}],["$","script",null,{"type":"text/javascript","async":true,"defer":true,"src":"/scripts/story-widget.js"}]]]]
M2:{"id":"9799","name":"","chunks":["544:d6e1aeb5-a0cd6c70e0c75eb3","541:541-9a7ed27eaa60a385","467:467-c3bf006142368b49","594:594-f55d59b38423cb14","621:621-562a0eec71b29bbf","531:531-61245aab4156da2f","493:493-763dfff1401403f4","929:929-d89874787c76a790","984:984-5d40795d22f21921","818:818-b6ce995c172fdce2","185:app/layout-c679f989968e7143"],"async":false}
M3:{"id":"9875","name":"","chunks":["272:webpack-b9aacdb8cf4e2fda","17:17-2f5f1c71a644e069","744:main-app-2aabd4f3728a103e"],"async":false}
M4:{"id":"2092","name":"","chunks":["272:webpack-b9aacdb8cf4e2fda","17:17-2f5f1c71a644e069","744:main-app-2aabd4f3728a103e"],"async":false}
M5:{"id":"2442","chunks":["994:b98bc7c3-8d93aa43aec73ea6","541:541-9a7ed27eaa60a385","594:594-f55d59b38423cb14","30:30-14a83a3970ed60db","299:299-17078d0866e06e38","665:app/(auth)/login/page-8cc2bf9fefe4ee19"],"name":"default","async":true}
J1:[[["$","link","static/media/2aaf0723e720e8b9.p.woff2",{"rel":"preload","href":"/_next/static/media/2aaf0723e720e8b9.p.woff2","as":"font","type":"font/woff2","crossOrigin":"anonymous"}]],[["$","link","0",{"rel":"stylesheet","href":"/_next/static/css/022c10a21f066f05.css","precedence":"high"}],["$","link","1",{"rel":"stylesheet","href":"/_next/static/css/37f27c40047a1ec9.css","precedence":"high"}],["$","link","2",{"rel":"stylesheet","href":"/_next/static/css/9a55bdf838cbf78d.css","precedence":"high"}],["$","link","3",{"rel":"stylesheet","href":"/_next/static/css/1c7718005413b6f0.css","precedence":"high"}]],["$","html",null,{"lang":"en","className":"__variable_79e26d","children":[["$","head",null,{}],["$","body",null,{"className":"font-sans","children":["$","@2",null,{"children":["$","@3",null,{"parallelRouterKey":"children","segmentPath":["children"],"hasLoading":false,"template":["$","@4",null,{}],"notFound":["$","div",null,{"style":{"fontFamily":"-apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", "Fira Sans", Avenir, "Helvetica Neue", "Lucida Grande", sans-serif","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":[["$","head",null,{"children":["$","title",null,{"children":"404: This page could not be found."}]}],["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"n            body { margin: 0; color: #000; background: #fff; }n            .next-error-h1 {n              border-right: 1px solid rgba(0, 0, 0, .3);n            }nn            @media (prefers-color-scheme: dark) {n              body { color: #fff; background: #000; }n              .next-error-h1 {n                border-right: 1px solid rgba(255, 255, 255, .3);n              }n            }n          "}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":0,"marginRight":"20px","padding":"0 23px 0 0","fontSize":"24px","fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block","textAlign":"left","lineHeight":"49px","height":"49px","verticalAlign":"middle"},"children":["$","h2",null,{"style":{"fontSize":"14px","fontWeight":"normal","lineHeight":"49px","margin":0,"padding":0},"children":"This page could not be found."}]}]]}]]}],"childProp":{"current":["$","@3",null,{"parallelRouterKey":"children","segmentPath":["children","(auth)","children"],"hasLoading":false,"template":["$","@4",null,{}],"childProp":{"current":["$","@3",null,{"parallelRouterKey":"children","segmentPath":["children","(auth)","children","login","children"],"hasLoading":false,"template":["$","@4",null,{}],"childProp":{"current":[[],[["$","link","0",{"rel":"stylesheet","href":"/_next/static/css/1c7718005413b6f0.css","precedence":"high"}]],["$","@5",null,{"params":{},"searchParams":{}}]],"segment":""},"rootLayoutIncluded":true}],"segment":"login"},"rootLayoutIncluded":true}],"segment":"(auth)"},"rootLayoutIncluded":true}]}]}]]}]]

不知道该尝试什么。我希望被重定向

这似乎是github上的一个开放问题,我有同样的问题,你描述的

•我更新到next的最新版本

•根据github线程的注释,我将这段代码片段添加到我的最低级别布局(ssr)中。

export const dynamic = 'force-dynamic'
export const revalidate = 0

https://github.com/vercel/next.js/issues/45595 issuecomment - 1445878897

相关内容

最新更新