Next.js Discord

Discord Forum

Type error: Route "app/api/auth/[...nextauth]/route.jsx" does not match the required types of a Next

Unanswered
Turkish Angora posted this in #help-forum
Open in Discord
Avatar
Turkish AngoraOP
i have to export it cause im using getServerSession, how do I fix it!?!?

16 Replies

Avatar
Clown
Paste the code of that route.jsx file here
Avatar
<Milind ツ />
It should be route.ts/js
Not route.tsx/jsx
.tsx/.jsx is used for writing UI
Avatar
joulev
this is not the cause, tsx/jsx is still fine
move the authOptions to a separate file and import it to your route.ts file
you must not export authOptions from the route.ts file itself
Avatar
<Milind ツ />
Not according to nextjs docs
Avatar
joulev
nextjs doesn't care if you use ts/js or the tsx/jsx variant. in fact if you want to use next/og in a route handler, you must use tsx because ts alone doesn't support jsx syntax
just try it
this page only shows that you can name your route with .ts/.js. it never explicitly said you can not name your route with .tsx/.jsx
Avatar
<Milind ツ />
True
Hmm interesting. Do not know about next/og. Will check that
Avatar
Turkish AngoraOP
ahh, will try when i get home
Avatar
Turkish AngoraOP
import DiscordProvider from 'next-auth/providers/discord';

export const authOptions = {
    session: {
        strategy: "jwt"
      },
  providers: [
    DiscordProvider({
      clientId: "1166465149167751269",
      clientSecret: "REDACTED",
    }),
  ],
  callbacks: {
    async jwt({ token, account }) {
      if (account) {
        try {
          const response = await fetch('https://discord.com/api/users/@me/guilds', {
            headers: {
              Authorization: `Bearer ${token}`,
            },
          });
          console.log(token)
        } catch {
          console.log("Couldn't connect to Discord")
          token.guilds = [];
        }
      }
      return token;
    },
    async session({ session, token }) {
      // @ts-expect-error
      session.accessToken = token.accessToken;
      // @ts-expect-error
      session.user.guilds = token.guilds
      return session;
    },
  },
};


./app/dashboard/request-admin/page.tsx:7:44
Type error: Argument of type '[{ session: { strategy: string; }; providers: OAuthConfig<DiscordProfile>[]; callbacks: { jwt({ token, account }: { token: any; account: any; }): Promise<any>; session({ session, token }: { ...; }): Promise<...>; }; }]' is not assignable to parameter of type 'GetServerSessionParams<GetServerSessionOptions>'.

5 | import axios from 'axios'
6 | const RequestAdmin = async () => {
7 | const session = await getServerSession(authOptions);
| ^
8 | console.log(session);
9 | var user = "";
10 | var role = "";