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

View File

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