Closed Noldius-Git closed 7 months ago
The problem come from the API next route
import SteamProvider, { PROVIDER_ID } from 'next-auth-steam'
import NextAuth from 'next-auth/next'
import type { NextRequest, NextResponse } from 'next/server'
import { AuthOptions } from "next-auth";
export function getAuthOptions(req: NextRequest): AuthOptions {
return {
providers: req
? [
SteamProvider(req, {
clientSecret: process.env.STEAM_SECRET!,
callbackUrl: 'http://localhost:3000/api/auth/callback',
}),
]
: [],
callbacks: {
jwt({ token, account, profile }) {
if (account?.provider === PROVIDER_ID) {
token.steam = profile;
}
return token;
},
session({ session, token }) {
if ('steam' in token) {
// @ts-expect-error
session.user.steam = token.steam;
}
return session;
},
},
};
}
async function handler(
req: NextRequest,
res: NextResponse,
ctx: { params: { nextauth: string[] } }
) {
// @ts-expect-error
return NextAuth(req, res, getAuthOptions(req));
}
export {
handler as GET,
handler as POST,
}
me to, how to solve this?
@Nekonyx hi, friend we need your help
@zoroblock @Noldius-Git Use NextApiRequest
and NextApiResponse
instead:
import SteamProvider, { PROVIDER_ID } from 'next-auth-steam'
import NextAuth, { AuthOptions } from 'next-auth/next'
import { NextApiRequest, NextApiResponse } from 'next';
export function getAuthOptions(req: NextApiRequest): AuthOptions {
return {
providers: req
? [
SteamProvider(req, {
clientSecret: process.env.STEAM_SECRET!,
callbackUrl: 'http://localhost:3000/api/auth/callback',
}),
]
: [],
callbacks: {
jwt({ token, account, profile }) {
if (account?.provider === PROVIDER_ID) {
token.steam = profile;
}
return token;
},
session({ session, token }) {
if ('steam' in token) {
// @ts-expect-error
session.user.steam = token.steam;
}
return session;
},
},
};
}
async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
return NextAuth(req, res, getAuthOptions(req));
}
export {
handler as GET,
handler as POST,
}
thanks bro ,but I have another problem @_@ @adrianlee
https://next-auth.js.org/errors#oauth_callback_error Unexpected token < in JSON at position 0 {
error: SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at parseJSONFromBytes (node:internal/deps/undici/undici:6662:19)
at successSteps (node:internal/deps/undici/undici:6636:27)
at node:internal/deps/undici/undici:1236:60
at node:internal/process/task_queues:140:7
at AsyncResource.runInAsyncScope (node:async_hooks:203:9)
at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
name: 'OAuthCallbackError',
code: undefined
},
providerId: 'steam',
message: 'Unexpected token < in JSON at position 0'
}
@Nekonyx same issue for me, Steam doesn't authorize. Do you know does it require a particular secret?
@Nekonyx same issue for me, Steam doesn't authorize. Do you know does it require a particular secret?
@Nekonyx same issue here too...
You have forgot to set your steam api key in the .env.local. Make sure you have added STEAM_SECRET="YOURKEY" from https://steamcommunity.com/dev/apikey
Seems like all issues are caused by forgotten Steam API key. v0.2.0 now throws an error if clientSecret
is not specified with some information. This should help to avoid such problems.
Auth doesn't work: "error - ReferenceError: res is not defined"
Maybe update to stable next app version, and try to resolve the bug.