Next.js Discord

Discord Forum

Error: Page "/api/auth/[...nextauth]" is missing "generateStaticParams()"

Answered
Argentine hake posted this in #help-forum
Open in Discord
Original message was deleted.
Answered by joulev
you are using static export which doesn't support next-auth since next-auth requires a server
View full answer

19 Replies

Original message was deleted
Hello, Show us your code in /api/auth/[...nextauth]/route.ts
Original message was deleted
you are using static export which doesn't support next-auth since next-auth requires a server
Answer
Argentine hake
next.config.js
/** @type {import('next').NextConfig} */
const MATRICULE = "x";
const nextConfig = {
  basePath: process.env.NODE_ENV === "production" ? `/~${MATRICULE}/APOD` : "",
  output: "export",
};

module.exports = nextConfig;
/api/auth/[...nextauth]/route.ts
import NextAuth from "next-auth";
import { authOptions } from "@/app/lib/auth";

const handler = NextAuth(authOptions);

export { handler as GET, handler as POST };


/lib/auth.ts
import axios from "axios";
import NextAuth, { AuthOptions } from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";

export const authOptions: AuthOptions = {
  providers: [
    CredentialsProvider({
      name: "Credentials",
      credentials: {
        email: { label: "email", type: "text" },
        password: { label: "password", type: "password" },
      },
      async authorize(credentials) {
        try {
          if (!credentials?.email || !credentials?.password) {
            return Promise.resolve(null);
          }
          const response = await axios.post(
            "https://x.x.x/user/signin",
            {
              email: credentials.email,
              password: credentials.password,
            }
          );

          if (response.status === 200) {
            const data = await response.data;
            return Promise.resolve({
              id: data.user.id,
              email: data.user.email,
              firstname: data.user.firstname,
              lastname: data.user.lastname,
              country: data.user.country,
              token: data.token,
            });
          } else {
            return Promise.resolve(null);
          }
        } catch (error) {
          console.error(error);
          return Promise.resolve(null);
        }
      },
    }),
  ],
  session: {
    strategy: "jwt",
  },
  debug: process.env.NODE_ENV === "development",
  callbacks: {
    async jwt({ token, user }) {
      return { ...token, ...user };
    },
    async session({ session, token }) {
      session.user = token as any;
      return session;
    },
  },
  secret: process.env.NEXTAUTH_SECRET,
};
@joulev you are using static export which doesn't support next-auth since next-auth requires a server
Argentine hake
Ok, so I want to retrieve the files with a next build to push them to a classic web server. I can't use next-auth?
@Argentine hake Ok, so I want to retrieve the files with a next build to push them to a classic web server. I can't use next-auth?
next-auth requires a server, so output: "export" cannot work with it
@joulev next-auth requires a server, so `output: "export"` cannot work with it
Argentine hake
Right, OK, do you have anything else interesting that could be used? Unfortunately, I only have the option of exporting my files.

In my situation, do I have to do everything "natively", i.e. do my own little fetch and create my session cookie?
all auth libraries require a server to parse and handle user requests
so if you want to implement auth with static export, your best bet would be client-side-based auth like firebase
@joulev so if you want to implement auth with static export, your best bet would be client-side-based auth like firebase
Argentine hake
In fact, I have to do a static export because my school doesn't have a node server. :/
Unfortunately, I don't have the option of using vercel or another server.
@Argentine hake In fact, I have to do a static export because my school doesn't have a node server. :/
yeah in this case you have to use client-based auth like firebase here (basically firebase has their own server that your client-side JS interacts with to get authentication details)
a server is still needed but it's firebase who manages that server, not you
(alternatives include e.g. supabase)
Argentine hake
yeah ok, in my case, i can just interact with rest api and i can't access to db x))))
Thanks for response ! Have a nice day
good luck with the project
not being able to have a running node server or hosting elsewhere is a very strict restriction...