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

javascript - Error: Page "apiauth[...nextauth]" is missing "generateStaticParams()" so it ca

programmeradmin1浏览0评论

I am working on Next.js project in which I have implemented user authentication using next-auth and Google Provider. When I am trying to create the build for the project the the plier throws this error "Error: Page "/api/auth/[...nextauth]" is missing "generateStaticParams()" so it cannot be used with "output: export" config." This is my api > auth > [...nextauth] > route.js file

import NextAuth from "next-auth";
import GoogleProvider from "next-auth/providers/google"

export const authoptions = {
    providers : [
        GoogleProvider({
            clientId : process.env.GOOGLE_CLIENT_ID,
            clientSecret : process.env.GOOGLE_CLIENT_SECRET
        })
    ],
    secret : process.env.NEXTAUTH_SECRET,
    callbacks : {
        async redirect(){
            return process.env.NEXTAUTH_URL;
        }
    }
}

const handler = NextAuth(authoptions)

export {handler as GET, handler as POST}

This is my code for api > auth > [...nextauth] > route.js file

/** @type {import('next').NextConfig} */
const nextConfig = {
    output : "export"
}

module.exports = nextConfig

This my code for next.config.js file

I am working on Next.js project in which I have implemented user authentication using next-auth and Google Provider. When I am trying to create the build for the project the the plier throws this error "Error: Page "/api/auth/[...nextauth]" is missing "generateStaticParams()" so it cannot be used with "output: export" config." This is my api > auth > [...nextauth] > route.js file

import NextAuth from "next-auth";
import GoogleProvider from "next-auth/providers/google"

export const authoptions = {
    providers : [
        GoogleProvider({
            clientId : process.env.GOOGLE_CLIENT_ID,
            clientSecret : process.env.GOOGLE_CLIENT_SECRET
        })
    ],
    secret : process.env.NEXTAUTH_SECRET,
    callbacks : {
        async redirect(){
            return process.env.NEXTAUTH_URL;
        }
    }
}

const handler = NextAuth(authoptions)

export {handler as GET, handler as POST}

This is my code for api > auth > [...nextauth] > route.js file

/** @type {import('next').NextConfig} */
const nextConfig = {
    output : "export"
}

module.exports = nextConfig

This my code for next.config.js file

Share Improve this question asked Nov 26, 2023 at 5:00 swetanshu singhswetanshu singh 611 silver badge3 bronze badges 6
  • do you have any dynamic route in your project? – Yilmaz Commented Nov 28, 2023 at 0:46
  • @Yilmaz yes I have a dynamic route. – swetanshu singh Commented Nov 28, 2023 at 1:47
  • does not this output : "export" mean you are building a static app – Yilmaz Commented Nov 28, 2023 at 1:48
  • yes, I read the docs and realized that I was creating the build wrong way. @Yilmaz Can you help in creating the build. I am not building a static app – swetanshu singh Commented Nov 28, 2023 at 1:59
  • just run npm run build?? – Yilmaz Commented Nov 28, 2023 at 2:06
 |  Show 1 more ment

1 Answer 1

Reset to default 8

If you are not building a static site then remove output : "export" from the nextConfig file. The authentication process is dynamic thus can not be rendered as static.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论