Getting next-auth-steam to work with create-t3-app

According to next-auth-steam's examples i should override jwt() and session() callbacks like this
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
}
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
}
https://github.com/Nekonyx/next-auth-steam/blob/master/examples/app-router-get-server-session/app/auth.ts#L17C7-L29C8 so I can access steam user data in session, i assume ? However this does not work in create-t3-app ( or maybe I am just missing out on something )
1 Reply
0xffff
0xffffOP9mo ago
I did some changes that theoretically should fix the issue, 1. declared next-auth/jwt so it has steam property
declare module "next-auth/jwt" {
interface JWT extends DefaultJWT {
steam?: any; // temp: just to get it working
}
}
declare module "next-auth/jwt" {
interface JWT extends DefaultJWT {
steam?: any; // temp: just to get it working
}
}
2. minimally modified callbacks
jwt({ token, account, profile }) {
if (account?.provider === PROVIDER_ID) token.steam = profile;

return token;
},
session: ({ session, token }) => ({
...session,
user: {
...session.user,
steam: token.steam ? token.steam : null // yes, i added steam field to Session interface aswell
},
}),
jwt({ token, account, profile }) {
if (account?.provider === PROVIDER_ID) token.steam = profile;

return token;
},
session: ({ session, token }) => ({
...session,
user: {
...session.user,
steam: token.steam ? token.steam : null // yes, i added steam field to Session interface aswell
},
}),
Unlucky this did not resolve issue and I am getting following session error
[next-auth][error][SESSION_ERROR]
https://next-auth.js.org/errors#session_error Cannot read properties of undefined (reading 'steam') {
message: "Cannot read properties of undefined (reading 'steam')",
stack: "TypeError: Cannot read properties of undefined (reading 'steam')\n" +
' at Object.session (/REDACTED_PATHNAME/.next/server/chunks/ssr/[root of the server]__01193f._.js:389:38)\n' +
' at Object.session (/REDACTED_PATHNAME/.next/server/chunks/ssr/node_modules_next-auth_afab3f._.js:2236:56)\n' +
' at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n' +
' at async AuthHandler (/REDACTED_PATHNAME/.next/server/chunks/ssr/node_modules_next-auth_afab3f._.js:3370:37)\n' +
' at async getServerSession (/REDACTED_PATHNAME/.next/server/chunks/ssr/node_modules_next-auth_afab3f._.js:3753:21)\n' +
' at async Home (/REDACTED_PATHNAME/.next/server/chunks/ssr/[root of the server]__01193f._.js:669:21)',
name: 'TypeError'
}
[next-auth][error][SESSION_ERROR]
https://next-auth.js.org/errors#session_error Cannot read properties of undefined (reading 'steam') {
message: "Cannot read properties of undefined (reading 'steam')",
stack: "TypeError: Cannot read properties of undefined (reading 'steam')\n" +
' at Object.session (/REDACTED_PATHNAME/.next/server/chunks/ssr/[root of the server]__01193f._.js:389:38)\n' +
' at Object.session (/REDACTED_PATHNAME/.next/server/chunks/ssr/node_modules_next-auth_afab3f._.js:2236:56)\n' +
' at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n' +
' at async AuthHandler (/REDACTED_PATHNAME/.next/server/chunks/ssr/node_modules_next-auth_afab3f._.js:3370:37)\n' +
' at async getServerSession (/REDACTED_PATHNAME/.next/server/chunks/ssr/node_modules_next-auth_afab3f._.js:3753:21)\n' +
' at async Home (/REDACTED_PATHNAME/.next/server/chunks/ssr/[root of the server]__01193f._.js:669:21)',
name: 'TypeError'
}
Maybe someone who understands way better than me, could give some hints, what am I missing out on
Want results from more Discord servers?
Add your server