javascript 使用下一个身份验证登录后Tailwind CSS未加载(next.js应用目录)

k2fxgqgv  于 2023-08-02  发布在  Java
关注(0)|答案(1)|浏览(86)

这是我的下一个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应用程序会发生这种行为。

s8vozzvw

s8vozzvw1#

我有CSS不加载问题与nextjs,nextauth和应用程序路由器。原来是因为我在tailwind.config.js中的配置错误。
我的问题来了,因为我初始化了nextjs项目,没有src目录,但后来我回顾性地添加了它,并且忽略了更新tailwind.config.js搞乱了CSS。
之前:

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    './pages/**/*.{js,ts,jsx,tsx,mdx}',
    './components/**/*.{js,ts,jsx,tsx,mdx}',
    './app/**/*.{js,ts,jsx,tsx,mdx}',
  ],
  ...
}

字符串
之后:

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    './src/pages/**/*.{js,ts,jsx,tsx,mdx}',
    './src/components/**/*.{js,ts,jsx,tsx,mdx}',
    './src/app/**/*.{js,ts,jsx,tsx,mdx}',
  ],
  ...
}

相关问题