Skip to content

Commit

Permalink
refactor: rename bffBasePath to bffBaseUrl for clarity
Browse files Browse the repository at this point in the history
Update variable names from `bffBasePath` to `bffBaseUrl` to enhance 
clarity and consistency across the codebase. This change improves 
the understanding of the code explicitly indicating that the 
variable represents a base URL rather than a path. Adjust related 
comments and event types to reflect this change.
  • Loading branch information
snaerth committed Dec 12, 2024
1 parent 62b7674 commit 92702c0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions libs/react-spa/bff/src/lib/BffPoller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const BffPoller = ({
const { signIn, bffUrlGenerator } = useAuth()
const userInfo = useUserInfo()
const { postMessage } = useBffBroadcaster()
const bffBasePath = bffUrlGenerator()
const bffBaseUrl = bffUrlGenerator()

const url = useMemo(
() => bffUrlGenerator('/user', { refresh: 'true' }),
Expand Down Expand Up @@ -87,7 +87,7 @@ export const BffPoller = ({
postMessage({
type: BffBroadcastEvents.NEW_SESSION,
userInfo: newUser,
bffBasePath,
bffBaseUrl,
})

newSessionCb()
Expand Down
16 changes: 8 additions & 8 deletions libs/react-spa/bff/src/lib/BffProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ export const BffProvider = ({
authState === 'logging-out'
const isLoggedIn = authState === 'logged-in'
const oldLoginPath = `${applicationBasePath}/login`
const bffBasePath = bffUrlGenerator()
const bffBaseUrl = bffUrlGenerator()

const { postMessage } = useBffBroadcaster((event) => {
/**
* Filter broadcast events by matching BFF base path
* Filter broadcast events by matching BFF base url
*
* Since the Broadcaster sends messages to all tabs/windows/iframes
* sharing the same origin (domain), we need to explicitly check if
* the message belongs to our specific BFF instance by comparing base paths.
* the message belongs to our specific BFF instance by comparing base urls.
* This prevents handling events meant for other applications/contexts
* running on the same domain.
*/
if (event.data.bffBasePath === bffBasePath) {
if (event.data.bffBaseUrl === bffBaseUrl) {
if (
isLoggedIn &&
event.data.type === BffBroadcastEvents.NEW_SESSION &&
Expand Down Expand Up @@ -83,10 +83,10 @@ export const BffProvider = ({
postMessage({
type: BffBroadcastEvents.NEW_SESSION,
userInfo: state.userInfo,
bffBasePath,
bffBaseUrl,
})
}
}, [postMessage, state.userInfo, isLoggedIn, bffBasePath])
}, [postMessage, state.userInfo, isLoggedIn, bffBaseUrl])

/**
* Builds authentication query parameters for login redirection:
Expand Down Expand Up @@ -188,13 +188,13 @@ export const BffProvider = ({
// Broadcast to all tabs/windows/iframes that the user is logging out
postMessage({
type: BffBroadcastEvents.LOGOUT,
bffBasePath,
bffBaseUrl,
})

window.location.href = bffUrlGenerator('/logout', {
sid: state.userInfo.profile.sid,
})
}, [bffUrlGenerator, postMessage, state.userInfo, bffBasePath])
}, [bffUrlGenerator, postMessage, state.userInfo, bffBaseUrl])

const switchUser = useCallback(
(nationalId?: string) => {
Expand Down
4 changes: 2 additions & 2 deletions libs/react-spa/bff/src/lib/bff.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ export enum BffBroadcastEvents {
type NewSessionEvent = {
type: BffBroadcastEvents.NEW_SESSION
userInfo: BffUser
bffBasePath: string
bffBaseUrl: string
}

type LogoutEvent = {
type: BffBroadcastEvents.LOGOUT
bffBasePath: string
bffBaseUrl: string
}

export type BffBroadcastEvent = NewSessionEvent | LogoutEvent
Expand Down

0 comments on commit 92702c0

Please sign in to comment.