Files
web/packages/trpc/lib/utils/getUserPointsBalance.ts
Joakim Jäderberg 291310e841 Merged in feature/curity-social-login (pull request #2963)
feat(SW-3541): Do social login after login to SAS

* feat(auth): wip social login via curity

* Setup social login auth flow

* Merge branch 'master' of bitbucket.org:scandic-swap/web into feature/curity-social-login

* Added support for getting scandic tokens and refresh them

* feat: Enhance social login and session management with auto-refresh and improved error handling

* Merge branch 'master' of bitbucket.org:scandic-swap/web into feature/curity-social-login

* wrap layout in suspense

* revert app/layout.tsx

* fix import

* cleanup

* merge

* merge

* dont pass client_secret in the url to curity

* add state validation when doing social login through /authorize

* remove debug logging


Approved-by: Anton Gunnarsson
2025-10-16 12:47:12 +00:00

31 lines
882 B
TypeScript

import { getEuroBonusProfileData } from "../routers/partners/sas/getEuroBonusProfile"
import { getVerifiedUser } from "../routers/user/utils/getVerifiedUser"
import { isValidSession } from "./session"
import type { Session } from "next-auth"
export async function getUserPointsBalance(
session: Session | null
): Promise<number | undefined> {
if (!isValidSession(session)) return undefined
const verifiedUser =
session.token.loginType === "sas"
? await getEuroBonusProfileData({
accessToken: session.token.access_token,
loginType: session.token.loginType,
})
: await getVerifiedUser({ session })
if (!verifiedUser || "error" in verifiedUser) {
return undefined
}
const points =
"points" in verifiedUser
? verifiedUser.points.total
: verifiedUser.data.membership?.currentPoints
return points ?? 0
}