Merged in feat/sw-3525-sas-member-type-in-tracking (pull request #2931)
feat(SW-3525): Set correct member type in tracking for partner-sas * Set correct member type in tracking for partner-sas Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -48,7 +48,10 @@ const config: NextAuthConfig = {
|
|||||||
async jwt(params) {
|
async jwt(params) {
|
||||||
if (params.trigger === "signIn") {
|
if (params.trigger === "signIn") {
|
||||||
const accessToken = params.account?.access_token
|
const accessToken = params.account?.access_token
|
||||||
|
// expires_at is in seconds for SAS, we need milliseconds
|
||||||
const expiresAt = params.account?.expires_at
|
const expiresAt = params.account?.expires_at
|
||||||
|
? params.account.expires_at * 1000
|
||||||
|
: null
|
||||||
|
|
||||||
if (!accessToken) {
|
if (!accessToken) {
|
||||||
throw new Error("AuthError: Missing access token")
|
throw new Error("AuthError: Missing access token")
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ type LoggedInScandicUserData = TrackingSDKUserDataBase & {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type LoggedInEurobonusUserData = TrackingSDKUserDataBase & {
|
type LoggedInEurobonusUserData = TrackingSDKUserDataBase & {
|
||||||
memberType: "eurobonus"
|
memberType: "sas-eurobonus"
|
||||||
}
|
}
|
||||||
|
|
||||||
type TrackingSDKUserDataBase = {
|
type TrackingSDKUserDataBase = {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export const useTrackingUserData = () => {
|
|||||||
const userData: TrackingSDKUserData | undefined = !isPending
|
const userData: TrackingSDKUserData | undefined = !isPending
|
||||||
? isError || !data
|
? isError || !data
|
||||||
? ({ loginStatus: "Error" } as const)
|
? ({ loginStatus: "Error" } as const)
|
||||||
: { ...data, memberType: "scandic-friends" }
|
: data
|
||||||
: undefined
|
: undefined
|
||||||
|
|
||||||
return { userData, isPending, isError }
|
return { userData, isPending, isError }
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export function createContext(opts: CreateContextOptions) {
|
|||||||
url: opts.url,
|
url: opts.url,
|
||||||
webToken: opts.webToken,
|
webToken: opts.webToken,
|
||||||
contentType: opts.contentType,
|
contentType: opts.contentType,
|
||||||
|
app: opts.app,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,8 +36,10 @@ export type TrackingUserData =
|
|||||||
membershipNumber?: string
|
membershipNumber?: string
|
||||||
memberLevel?: MembershipLevel
|
memberLevel?: MembershipLevel
|
||||||
loginAction?: "login success"
|
loginAction?: "login success"
|
||||||
|
memberType: "scandic-friends" | "sas-eurobonus"
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
loginStatus: "Non-logged in"
|
loginStatus: "Non-logged in"
|
||||||
|
memberType: "scandic-friends" | "sas-eurobonus"
|
||||||
}
|
}
|
||||||
| { loginStatus: "Error" }
|
| { loginStatus: "Error" }
|
||||||
|
|||||||
@@ -6,22 +6,38 @@ import { getFriendsMembership } from "../helpers"
|
|||||||
import { getVerifiedUser } from "../utils/getVerifiedUser"
|
import { getVerifiedUser } from "../utils/getVerifiedUser"
|
||||||
|
|
||||||
import type { LoginType } from "@scandic-hotels/common/constants/loginType"
|
import type { LoginType } from "@scandic-hotels/common/constants/loginType"
|
||||||
|
import type { Session } from "next-auth"
|
||||||
|
|
||||||
import type { TrackingUserData } from "../../types"
|
import type { TrackingUserData } from "../../types"
|
||||||
|
|
||||||
export const userTrackingInfo = safeProtectedProcedure.query(async function ({
|
export const userTrackingInfo = safeProtectedProcedure.query(async function ({
|
||||||
ctx,
|
ctx,
|
||||||
}) {
|
}) {
|
||||||
|
if (ctx.app === "partner-sas") {
|
||||||
|
return getSasEurobonusUserTrackingData(ctx.session)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx.app === "scandic-web") {
|
||||||
|
return getScandicFriendsUserTrackingData(ctx.session)
|
||||||
|
}
|
||||||
|
|
||||||
|
return { loginStatus: "Error" } as const
|
||||||
|
})
|
||||||
|
|
||||||
|
async function getScandicFriendsUserTrackingData(session: Session | null) {
|
||||||
const userTrackingInfoCounter = createCounter("user", "userTrackingInfo")
|
const userTrackingInfoCounter = createCounter("user", "userTrackingInfo")
|
||||||
const metricsUserTrackingInfo = userTrackingInfoCounter.init()
|
const metricsUserTrackingInfo = userTrackingInfoCounter.init()
|
||||||
|
|
||||||
metricsUserTrackingInfo.start()
|
metricsUserTrackingInfo.start()
|
||||||
|
|
||||||
|
const memberType = "scandic-friends" as const
|
||||||
|
|
||||||
const notLoggedInUserTrackingData: TrackingUserData = {
|
const notLoggedInUserTrackingData: TrackingUserData = {
|
||||||
loginStatus: "Non-logged in",
|
loginStatus: "Non-logged in",
|
||||||
|
memberType,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isValidSession(ctx.session)) {
|
if (!isValidSession(session)) {
|
||||||
metricsUserTrackingInfo.success({
|
metricsUserTrackingInfo.success({
|
||||||
reason: "invalid session",
|
reason: "invalid session",
|
||||||
data: notLoggedInUserTrackingData,
|
data: notLoggedInUserTrackingData,
|
||||||
@@ -30,7 +46,7 @@ export const userTrackingInfo = safeProtectedProcedure.query(async function ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const verifiedUserData = await getVerifiedUser({ session: ctx.session })
|
const verifiedUserData = await getVerifiedUser({ session: session })
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!verifiedUserData ||
|
!verifiedUserData ||
|
||||||
@@ -48,11 +64,12 @@ export const userTrackingInfo = safeProtectedProcedure.query(async function ({
|
|||||||
|
|
||||||
const loggedInUserTrackingData: TrackingUserData = {
|
const loggedInUserTrackingData: TrackingUserData = {
|
||||||
loginStatus: "logged in",
|
loginStatus: "logged in",
|
||||||
loginType: ctx.session.token.loginType as LoginType,
|
loginType: session.token.loginType as LoginType,
|
||||||
memberId: verifiedUserData.data.profileId,
|
memberId: verifiedUserData.data.profileId,
|
||||||
membershipNumber: membership?.membershipNumber,
|
membershipNumber: membership?.membershipNumber,
|
||||||
memberLevel: membership?.membershipLevel,
|
memberLevel: membership?.membershipLevel,
|
||||||
loginAction: "login success",
|
loginAction: "login success",
|
||||||
|
memberType,
|
||||||
}
|
}
|
||||||
|
|
||||||
metricsUserTrackingInfo.success({
|
metricsUserTrackingInfo.success({
|
||||||
@@ -65,4 +82,28 @@ export const userTrackingInfo = safeProtectedProcedure.query(async function ({
|
|||||||
metricsUserTrackingInfo.fail(error)
|
metricsUserTrackingInfo.fail(error)
|
||||||
return notLoggedInUserTrackingData
|
return notLoggedInUserTrackingData
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
async function getSasEurobonusUserTrackingData(session: Session | null) {
|
||||||
|
const notLoggedInUserTrackingData: TrackingUserData = {
|
||||||
|
loginStatus: "Non-logged in",
|
||||||
|
memberType: "sas-eurobonus",
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isValidSession(session)) {
|
||||||
|
return notLoggedInUserTrackingData
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const loggedInUserTrackingData: TrackingUserData = {
|
||||||
|
loginStatus: "logged in",
|
||||||
|
loginType: session.token.loginType,
|
||||||
|
loginAction: "login success",
|
||||||
|
memberType: "sas-eurobonus",
|
||||||
|
}
|
||||||
|
|
||||||
|
return loggedInUserTrackingData
|
||||||
|
} catch (_error) {
|
||||||
|
return notLoggedInUserTrackingData
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user