这是我的下一个auth选项:
import CredentialsProvider from "next-auth/providers/credentials";
import { type AuthOptions } from "next-auth";
export const nextAuthOptions: AuthOptions = {
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
username: { label: "Username", type: "text", placeholder: "jsmith" },
password: { label: "Password", type: "password" },
},
async authorize(credentials: any, req): Promise<any> {
const user = {
name: credentials.email,
id: Math.random(),
email: credentials.email,
password: credentials.PhoneOtp,
};
if (user) {
return user;
} else {
return null;
}
},
}),
],
callbacks: {
async signIn() {
return true;
},
async jwt({ token, user, trigger, session }: any) {
if (trigger === "update") {
return { ...token, ...session.user };
}
return { ...token, ...user };
} ,
async session({ session, token }: any) {
session.user = token;
return session;
},
},
session: {
maxAge: 60 * 60, // 1 hour in seconds
strategy: "jwt",
},
pages: {
signIn: "/signin", // Custom sign-in screen URL
},
字符串
};
这是我的下一个中间件文件:
export { default } from "next-auth/middleware";
export const config = {
matcher: ["/posts", "/home"],
};
型
在一个客户端组件中,我这样登录:
await signIn("credentials", {
email: userInfo.email,
password: watch("Phone_otp"),
redirect: true,
// accessToken: JSON.stringify(data.response),
callbackUrl: "/home",
})
.then(() => {
dispatch({
type: reducerActions.HIDE_LOADER,
});
router.push("/home");
console.log("then executed >");
// redirect("/home");
})
.catch((err: any) => {
dispatch({
type: reducerActions.HIDE_LOADER,
});
console.log(" signin err > ", err);
});
型
但在登录后,顺风css是没有得到加载,即使在做了硬重新加载,但当某个时候,我得到了未经授权的页面,并回来,然后css是加载。我不知道为什么我的下一个js应用程序会发生这种行为。
1条答案
按热度按时间s8vozzvw1#
我有CSS不加载问题与nextjs,nextauth和应用程序路由器。原来是因为我在
tailwind.config.js
中的配置错误。我的问题来了,因为我初始化了nextjs项目,没有
src
目录,但后来我回顾性地添加了它,并且忽略了更新tailwind.config.js
搞乱了CSS。之前:
字符串
之后:
型