Merged in feature/SW-3539-log-number-of-logins (pull request #3284)

feat(SW-3539): count number of logins

* feat(SW-3539): count number of logins


Approved-by: Anton Gunnarsson
This commit is contained in:
Joakim Jäderberg
2025-12-03 09:50:59 +00:00
parent 99497488f3
commit a016e18e4a
3 changed files with 21 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ import Auth0Provider from "next-auth/providers/auth0"
import { dt } from "@scandic-hotels/common/dt"
import { createLogger } from "@scandic-hotels/common/logger/createLogger"
import { createCounter } from "@scandic-hotels/common/telemetry"
import { safeTry } from "@scandic-hotels/common/utils/safeTry"
import { getEuroBonusProfileData } from "@scandic-hotels/trpc/routers/partners/sas/getEuroBonusProfile"
@@ -13,6 +14,8 @@ import type { JWT } from "next-auth/jwt"
const authLogger = createLogger("auth")
export const PRE_REFRESH_TIME_IN_SECONDS = 180
export const signInCounter = createCounter("auth", "signIn")
async function refreshTokens(token: JWT) {
try {
if (!token.refresh_token) {
@@ -118,6 +121,7 @@ const config: NextAuthConfig = {
async jwt(params) {
if (params.trigger === "signIn") {
const counter = signInCounter.init({ type: "sas" })
const accessToken = params.account?.access_token
// expires_at is in seconds for SAS, we need milliseconds
const expiresAt = params.account?.expires_at
@@ -125,16 +129,19 @@ const config: NextAuthConfig = {
: null
if (!accessToken) {
counter.fail("missing access token")
throw new Error("AuthError: Missing access token")
}
if (!expiresAt) {
counter.fail("missing expiry time")
throw new Error("AuthError: Missing expiry time")
}
const refreshToken = params.account?.refresh_token
if (!refreshToken) {
counter.fail("missing refresh token")
authLogger.warn("⚠️ refreshToken missing")
}
@@ -146,6 +153,7 @@ const config: NextAuthConfig = {
authLogger.error("Failed to fetch EuroBonus profile", error)
}
counter.success()
return {
...params.token,
isLinked: eurobonusProfile?.linkStatus === "LINKED",