Next.js Discord

Discord Forum

Module not found w/ next-auth

Answered
Mugger Crocodile posted this in #help-forum
Open in Discord
Avatar
Mugger CrocodileOP
folder structure
app
  api
    auth
      [...nextauth]
        route.ts
  account
    guilds
      page.tsx
  lib
    auth.ts

auth.ts:
import NextAuth from "next-auth";
import DiscordProvider from "next-auth/providers/discord";
import "dotenv/config";

export const { auth, handlers: { GET, POST } } = NextAuth({
    providers: [
        DiscordProvider({
            clientId: process.env.CLIENT_ID ?? "",
            clientSecret: process.env.CLIENT_SECRET ?? ""
        })
    ],
    secret: process.env.NEXTAUTH_URL
});

pages.tsx
import { redirect } from "next/navigation.js";
import { auth } from "@/app/lib/auth.js";
import styles from "../../page.module.css";

export default async function GuildsPage() {
    const session = await auth();

    if (!session) redirect("/api/auth/signin");
    return (
        <main className={styles.description}>
            <p>
                Guilds Page
            </p>
            <p>Welcome {session.user?.name}!</p>
        </main>
    );
}

route.ts
export { GET, POST } from "@/app/lib/auth.js";

error:
 ⨯ ./src/app/api/auth/[...nextauth]/route.ts:1:0
Module not found: Can't resolve '@/app/lib/auth.js'
> 1 | export { GET, POST } from "@/app/lib/auth.js";
Answered by Mugger Crocodile
i solved the issue by using "allowImportingTsExtensions": true, and setting auth.js to auth.ts
View full answer

8 Replies

Avatar
Mugger CrocodileOP
Using Bun
Next: 14.0.4
NextAuth: 5.0.0-beta.5
Ive tried using "use client" and "use server". doesnt help
Avatar
could you try with npm/yarn/pnpm?
Avatar
Mugger CrocodileOP
sure
nope...
still causing an error
Avatar
export { GET, POST } from "@/app/lib/auth";
Avatar
Mugger CrocodileOP
i solved the issue by using "allowImportingTsExtensions": true, and setting auth.js to auth.ts
Answer