最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

performance - NextJS takes time to process requests - Stack Overflow

programmeradmin0浏览0评论

I have a SaaS in NextJS, and for some reason, it happens that when I make a request even if it has no logic other than validating the path with Next Auth or even without that, the fetch takes a few seconds to process and display the information, since I have a loader, and that loader takes, I have been reviewing the code and I have not yet found the part that affects performance.

I don't know if there is any way to optimize the routes.

app/api/auth/[...nextauth].ts

import NextAuth from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";

export default NextAuth({
  providers: [
    CredentialsProvider({
      name: "Credentials",
      credentials: {
        username: { label: "Username", type: "text" },
        password: { label: "Password", type: "password" }
      },
      authorize(credentials) {
        if (credentials?.username === "user" && credentials?.password === "pass") {
          return { id: 1, name: "Example User" };
        }
        return null;
      }
    })
  ],
  pages: {
    signIn: "/auth/signin"
  }
});

app/protected.tsx

import { getSession } from "next-auth/react";

export default function ProtectedPage() {
  return <h1>This is a protected page</h1>;
};

export async function getServerSideProps(context: any) {
  const session = await getSession(context);

  if (!session) {
    return {
      redirect: {
        destination: "/auth/signin",
        permanent: false
      }
    };
  }

  return {
    props: {}
  };
}

app/auth/signin.tsx

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

export default function SignIn() {
  return (
    <div>
      <h1>Sign In</h1>
      <button onClick={() => signIn()}>Sign in with credentials</button>
    </div>
  );
};
发布评论

评论列表(0)

  1. 暂无评论