#Module not found w/ next-auth

10 messages · Page 1 of 1 (latest)

queen scroll
#

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";
fringe oliveBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

queen scroll
#

Using Bun
Next: 14.0.4
NextAuth: 5.0.0-beta.5

#

Ive tried using "use client" and "use server". doesnt help

lilac gale
queen scroll
#

sure

#

nope...

#

still causing an error

lilac gale
#

export { GET, POST } from "@/app/lib/auth";

queen scroll
#

i solved the issue by using "allowImportingTsExtensions": true, and setting auth.js to auth.ts