Merged in fix/sw-3627-pass-user-access-token-payment-callback (pull request #3189)

fix(SW-3627): Pass social session user token to payment callback apge

* Pass social session user token to payment callback apge


Approved-by: Linus Flood
This commit is contained in:
Anton Gunnarsson
2025-11-20 12:36:40 +00:00
parent bd85dd3b49
commit 36cd1a5cdf
2 changed files with 31 additions and 11 deletions

View File

@@ -3,6 +3,8 @@ import { logger } from "@scandic-hotels/common/logger"
import { bookingFlowConfig } from "@/constants/bookingFlowConfig"
import { getSocialSession, isValidSocialSession } from "@/auth/scandic/session"
import type { PaymentCallbackStatusEnum } from "@scandic-hotels/common/constants/paymentCallbackStatusEnum"
import type { LangParams, PageArgs } from "@/types/params"
@@ -15,12 +17,11 @@ export default async function PaymentCallbackPage(
logger.debug(`[payment-callback] callback started`)
const lang = params.lang
const userAccessToken = null
// TODO fix when auth is implemented
// const session = await auth()
// if (isValidSession(session)) {
// userAccessToken = session.token.access_token
// }
let userAccessToken = null
const session = await getSocialSession()
if (isValidSocialSession(session)) {
userAccessToken = session.access_token
}
return (
<PaymentCallbackPagePrimitive

View File

@@ -7,12 +7,13 @@ import { dt } from "@scandic-hotels/common/dt"
import { env } from "@/env/server"
async function internalGetSession() {
return await getIronSession<{
type SocialSession = {
access_token: string
refresh_token: string | undefined
refresh_token?: string
expires_at: string
}>(await cookies(), {
}
async function internalGetSession() {
return await getIronSession<SocialSession>(await cookies(), {
password: env.IRON_SESSION_SECRET,
cookieName: "scandic_session",
})
@@ -54,3 +55,21 @@ export async function destroySocialSession() {
session.destroy()
}
export function isValidSocialSession(
session: SocialSession | null
): session is SocialSession {
if (!session) {
return false
}
if (!session.access_token) {
return false
}
if (session.expires_at && dt(session.expires_at).isBefore(dt())) {
return false
}
return true
}