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
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Turkish AngoraOP
i have to export it cause im using getServerSession, how do I fix it!?!?
16 Replies
![Avatar](https://cdn.discordapp.com/avatars/678259999201427466/1936f7e8963ff0f800f5eb4b43bc833c.webp?size=256)
Clown
Paste the code of that route.jsx file here
![Avatar](https://cdn.discordapp.com/avatars/397055198545051650/1845f5dc6f66f45bf8fa6942f3b5133b.webp?size=256)
<Milind ツ />
It should be route.ts/js
Not route.tsx/jsx
.tsx/.jsx is used for writing UI
![Avatar](https://cdn.discordapp.com/avatars/484037068239142956/44415017de6fed2ccd5d44b4b2051ac0.webp?size=256)
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
fileyou must not export
authOptions
from the route.ts
file itself![Avatar](https://cdn.discordapp.com/avatars/397055198545051650/1845f5dc6f66f45bf8fa6942f3b5133b.webp?size=256)
<Milind ツ />
Not according to nextjs docs
![Avatar](https://cdn.discordapp.com/avatars/484037068239142956/44415017de6fed2ccd5d44b4b2051ac0.webp?size=256)
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 syntaxjust 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](https://cdn.discordapp.com/avatars/397055198545051650/1845f5dc6f66f45bf8fa6942f3b5133b.webp?size=256)
<Milind ツ />
True
Hmm interesting. Do not know about next/og. Will check that
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
Turkish AngoraOP
ahh, will try when i get home
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
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 = "";