Closed maxeth closed 1 year ago
I came up with this solution (?):
export default function handler(req: NextApiRequest, res: NextApiResponse) {
return NextAuth(req, res, authOptions(req));
}
export function authOptions(req: NextApiRequest): AuthOptions {
return {
providers: [
SteamProvider(req, {
[...]
}]
}
}
and then pass the req object to authOptions
to get a config object that getServerSession
accepts:
const session = await getServerSession(req, res, authOptions(req));
This hasn't caused any unexpected behaviour so far, and after taking a look at what this package does with req
internally, I don't see any issue with this solution at first glance.
I'm still interested in how you guys deal with getServerSession
and this package π
Hey @maxeth, thanks for your interest in my project.
There's an example of using getServerSession
: https://github.com/Nekonyx/next-auth-steam/tree/master/examples/get-server-session
In short, yes, we get auth options in method:
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
return NextAuth(req, res, getAuthOptions(req))
}
export function getAuthOptions(req: NextApiRequest): AuthOptions {
return {
providers: [
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
}
}
}
}
Hey,
first of all, thanks for this easy Steam OAuth integration.
The next-auth docs mention the following snippet with
getServerSession
for getting a user's session within API routes (I came across it as my attempt to get the session withgetSession({req})
returnsnull
within my API routes):Here,
authOptions
- e.g the object with {providers: [...], secret: [...]} - has to be passed as a "pure" object.Your README, however, shows a setup like this in
[...nextauth].ts
:So the
SteamProvider
expects areq
. This makes their way of passing theauthOptions
as a pure object impossible when using your package as one of the providers, or am I missing something?Now I'm wondering: is there a common way to use getServerSession with your Steam OAuth integration? Or am I the only one getting
null
when callinggetSession({req})
inside API routes? π