-
hey folks, I am trying to upgrade the setup to V5 with a very basic auth file (I commented the code to test it out), TypeScript compiler is giving me some trouble: import NextAuth, { NextAuthConfig } from 'next-auth';
const config = {
} satisfies NextAuthConfig;
export const { handlers, auth, signIn, signOut } = NextAuth(config);
|
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 18 replies
-
Hey @ThangHuuVu, I sincerely apologize for tagging you directly. I am unsure what to do anymore. Have you seen this issue before or know what the issue is with TypeScript? PR: https://github.com/straw-hat-team/nextjs-starter-kit/pull/157 |
Beta Was this translation helpful? Give feedback.
-
After trying multiple things following microsoft/TypeScript#42873 I decided to add to my Next Apps computation: {
"compilerOptions": {
"declaration": false,
}
} It is fixed under I am not sure what the downsides are doing that, |
Beta Was this translation helpful? Give feedback.
-
I am having the same issue but with the
My code : import NextAuth from 'next-auth';
import Entra from 'next-auth/providers/microsoft-entra-id';
const {
AZURE_ENTRA_TENANT_ID,
AZURE_ENTRA_CLIENT_ID,
AZURE_ENTRA_CLIENT_SECRET,
} = process.env;
export const { auth, handlers, signIn, signOut } : NextAuthResult = NextAuth({ // The signIn is marked as error
providers: [
Entra({
tenantId: AZURE_ENTRA_TENANT_ID,
clientId: AZURE_ENTRA_CLIENT_ID,
clientSecret: AZURE_ENTRA_CLIENT_SECRET,
}),
],
}); |
Beta Was this translation helpful? Give feedback.
-
Actually I don't know why this is closed, the problem persists, trying to fix the Profiles I got to: import NextAuth, { NextAuthConfig, NextAuthResult } from "next-auth";
import GoogleProvider, { GoogleProfile } from "next-auth/providers/google";
import MicrosoftEntraProvider, { MicrosoftEntraIDProfile } from "next-auth/providers/microsoft-entra-id";
// Define explicit types for the NextAuth configuration
const authOptions: NextAuthConfig = {
providers: [
GoogleProvider({
authorization: {
params: {
prompt: "consent",
access_type: "offline",
response_type: "code",
},
},
}),
MicrosoftEntraProvider({
clientId: process.env.AUTH_MICROSOFT_ENTRA_ID_ID || '',
clientSecret: process.env.AUTH_MICROSOFT_ENTRA_ID_SECRET || '',
issuer: `https://login.microsoftonline.com/${process.env.AUTH_MICROSOFT_ENTRA_ID_TENANT || 'common'}/v2.0`,
authorization: {
params: {
scope: 'openid profile email User.Read',
prompt: 'select_account'
}
}
})
],
session: { strategy: "jwt" },
pages: {
signIn: "/login",
}
};
// Infer the return type of NextAuth
type NextAuthReturnType = NextAuthResult;
type Profiles = GoogleProfile | MicrosoftEntraIDProfile;
// Define custom types for signIn and signOut with correct generics
type CustomSignIn = <P extends Profiles, R extends boolean = true>(
provider?: P,
options?:
| FormData
| ({
redirectTo?: string
redirect?: R
} & Record<string, any>),
authorizationParams?:
| string[][]
| Record<string, string>
| string
| URLSearchParams
) => Promise<R extends false ? any : never>;
type CustomSignOut = NextAuthReturnType['signOut'];
// Export the handlers explicitly with custom types
export const { handlers, signIn, signOut, auth } = NextAuth(authOptions) as {
handlers: NextAuthReturnType['handlers'];
signIn: CustomSignIn;
signOut: CustomSignOut;
auth: NextAuthReturnType['auth'];
}; but, it definitely doesn't seem like a reasonable solution to me, @Falven's solution worked for me, I'll copy the error in my native language, so that other people can also find this solution The solution proposed by @Falven and it worked for me was: const result = NextAuth(authOptions);
export const handlers: NextAuthResult['handlers'] = result.handlers;
export const auth: NextAuthResult['auth'] = result.auth;
export const signIn: NextAuthResult['signIn'] = result.signIn;
export const signOut: NextAuthResult['signOut'] = result.signOut; I found the issue for this here #10568 |
Beta Was this translation helpful? Give feedback.
-
I believe this is related to the setup in // tsconfig.json
{
"extends": "@repo/typescript-config/nextjs.json",
"compilerOptions": {
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["**/*.ts", "**/*.tsx", "next-env.d.ts", "next.config.js", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
// typescript-config/nextjs.json
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./base.json",
"compilerOptions": {
"plugins": [{ "name": "next" }],
"module": "ESNext",
"moduleResolution": "Bundler",
"allowJs": true,
"jsx": "preserve",
"noEmit": true
}
}
Whilst the original does work: // working tsconfig.json
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
|
Beta Was this translation helpful? Give feedback.
-
From @Falven, check #9950 (reply in thread) One option is to explicitly re-type the destructed declarations. import authOptions from './config/auth.config';
import NextAuth, { type NextAuthResult } from 'next-auth';
const result = NextAuth(authOptions);
export const handlers: NextAuthResult['handlers'] = result.handlers;
export const auth: NextAuthResult['auth'] = result.auth;
export const signIn: NextAuthResult['signIn'] = result.signIn;
export const signOut: NextAuthResult['signOut'] = result.signOut; This avoids the naming issue because each property is typed individually and doesn't require a single stable type name for the entire object. But it's really up to next-auth to make their declarations more stable. |
Beta Was this translation helpful? Give feedback.
-
Thanks for providing a workaround. Explicitly re-typing the declarations is a bit ugly though, I hope this gets addressed. |
Beta Was this translation helpful? Give feedback.
From @Falven, check #9950 (reply in thread)
One option is to explicitly re-type the destructed declarations.
This avoids the naming issue because each property is typed individually and doesn't require a single stable type name for the entire object. But it's really up to next-auth to make thei…