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:
@@ -2,6 +2,7 @@ import NextAuth, { type NextAuthConfig, type User } from "next-auth"
|
||||
|
||||
import { LoginTypeEnum } from "@scandic-hotels/common/constants/loginType"
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
import { createCounter } from "@scandic-hotels/common/telemetry"
|
||||
|
||||
import { PRE_REFRESH_TIME_IN_SECONDS } from "@/constants/auth"
|
||||
import { env } from "@/env/server"
|
||||
@@ -9,6 +10,8 @@ import { env } from "@/env/server"
|
||||
import type { JWT } from "next-auth/jwt"
|
||||
import type { OIDCConfig } from "next-auth/providers"
|
||||
|
||||
export const signInCounter = createCounter("auth", "signIn")
|
||||
|
||||
function getLoginType(user: User) {
|
||||
if (user?.login_with.includes("@")) {
|
||||
return LoginTypeEnum.email
|
||||
@@ -177,6 +180,9 @@ const baseConfig = {
|
||||
async jwt({ account, session, token, trigger, user, profile }) {
|
||||
const loginType = getLoginType(user)
|
||||
if (trigger === "signIn" && account) {
|
||||
const counter = signInCounter.init({ type: "curity" })
|
||||
counter.success()
|
||||
|
||||
const mfa_scope = profile?.amr == "urn:com:scandichotels:scandic-otp"
|
||||
const tokenExpiry = account.expires_at
|
||||
? account.expires_at * 1000
|
||||
|
||||
Reference in New Issue
Block a user