Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/apps/platform/src/components/app-header/AppHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import classNames from 'classnames'
import { EnvironmentConfig, PageSubheaderPortalId } from '~/config'
import {
authUrlLogin,
authUrlLogout,
authUrlSignup,
profileContext,
ProfileContextData,
routerContext,
RouterContextData,
} from '~/libs/core'
import { ConfigContextValue, useConfigContext } from '~/libs/shared'

import UniNavSnippet from './universal-nav-snippet'

Expand All @@ -39,6 +39,7 @@ const AppHeader: FC<{}> = () => {

const { activeToolName, activeToolRoute }: RouterContextData = useContext(routerContext)
const { profile, initialized: profileReady }: ProfileContextData = useContext(profileContext)
const { logoutUrl }: ConfigContextValue = useConfigContext()
const [ready, setReady]: [boolean, Dispatch<SetStateAction<boolean>>] = useState<boolean>(false)
const headerInit: MutableRefObject<boolean> = useRef(false)
const navElementId: string = PageSubheaderPortalId
Expand Down Expand Up @@ -95,7 +96,7 @@ const AppHeader: FC<{}> = () => {
},
onReady() { setReady(true) },
signIn() { window.location.href = authUrlLogin() },
signOut() { window.location.href = authUrlLogout },
signOut() { window.location.href = logoutUrl },
signUp() { window.location.href = authUrlSignup() },
toolName: activeToolName,
toolRoot: activeToolRoute,
Expand All @@ -110,6 +111,7 @@ const AppHeader: FC<{}> = () => {
navigationHandler,
userInfo,
profileReady,
logoutUrl,
])

// update uni-nav's tool details
Expand Down Expand Up @@ -141,12 +143,14 @@ const AppHeader: FC<{}> = () => {
navElementId,
{
...userInfo,
signOut() { window.location.href = logoutUrl },
},
)
}, [
profileReady,
userInfo,
navElementId,
logoutUrl,
])

return (
Expand Down
15 changes: 9 additions & 6 deletions src/apps/platform/src/providers/Providers.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FC, ReactNode } from 'react'

import { ProfileProvider } from '~/libs/core'
import { authUrlLogout, ProfileProvider } from '~/libs/core'
import { ConfigContextProvider } from '~/libs/shared'

import { PlatformRouterProvider } from './platform-router.provider'

Expand All @@ -9,11 +10,13 @@ interface ProvidersProps {
}

const Providers: FC<ProvidersProps> = props => (
<ProfileProvider>
<PlatformRouterProvider>
{props.children}
</PlatformRouterProvider>
</ProfileProvider>
<ConfigContextProvider logoutUrl={authUrlLogout}>
<ProfileProvider>
<PlatformRouterProvider>
{props.children}
</PlatformRouterProvider>
</ProfileProvider>
</ConfigContextProvider>
)

export default Providers
13 changes: 9 additions & 4 deletions src/apps/profiles/src/ProfilesApp.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { FC, useContext } from 'react'
import { FC, useContext, useEffect } from 'react'
import { Outlet, Routes } from 'react-router-dom'

import { routerContext, RouterContextData } from '~/libs/core'
import { SharedSwrConfig } from '~/libs/shared'
import { authUrlLogin, authUrlLogoutFn, routerContext, RouterContextData } from '~/libs/core'
import { ConfigContextValue, SharedSwrConfig, useConfigContext } from '~/libs/shared'

import { toolTitle } from './profiles.routes'
import { absoluteRootRoute, toolTitle } from './profiles.routes'

const ProfilesApp: FC<{}> = () => {
const { setLogoutUrl }: ConfigContextValue = useConfigContext()
const { getChildRoutes }: RouterContextData = useContext(routerContext)

useEffect(() => {
setLogoutUrl(authUrlLogoutFn(authUrlLogin(absoluteRootRoute)))
}, [setLogoutUrl])

return (
<SharedSwrConfig>
<Outlet />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ export function login(returnUrl?: string): string {
return `${authentication}?retUrl=${encodeURIComponent(retUrl)}`
}

export const logout: string
= `${authentication}?logout=true&retUrl=${encodeURIComponent(`https://${window.location.host}`)}`
export const logoutFn = (retUrl: string): string => (
`${authentication}?logout=true&retUrl=${encodeURIComponent(retUrl)}`
)

export const logout: string = logoutFn(`https://${window.location.host}`)

export function signup(returnUrl?: string, regSource?: AuthenticationRegistrationSource): string {
return `${login(returnUrl)}&mode=signUp${!!regSource ? `&regSource=${regSource}` : ''}`
Expand Down
1 change: 1 addition & 0 deletions src/libs/core/lib/auth/authentication-functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export {
authentication as authUrl,
login as authUrlLogin,
logout as authUrlLogout,
logoutFn as authUrlLogoutFn,
signup as authUrlSignup,
} from './authentication-url.config'
export {
Expand Down
34 changes: 34 additions & 0 deletions src/libs/shared/lib/contexts/config.context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { createContext, FC, ReactNode, useContext, useMemo, useState } from 'react'

export interface ConfigContextValue {
logoutUrl: string
setLogoutUrl: (logoutUrl: string) => void
}

const ConfigReactCtx = createContext<ConfigContextValue>({} as ConfigContextValue)

interface ConfigContextProps {
children?: ReactNode
logoutUrl: string
}

export const ConfigContextProvider: FC<ConfigContextProps> = props => {
const [logoutUrl, setLogoutUrl] = useState<string>(props.logoutUrl)

const contextValue = useMemo(() => ({
logoutUrl,
setLogoutUrl,
}), [setLogoutUrl, logoutUrl])

return (
<ConfigReactCtx.Provider
value={contextValue}
>
{props.children}
</ConfigReactCtx.Provider>
)
}

export const useConfigContext = (): ConfigContextValue => (
useContext(ConfigReactCtx)
)
1 change: 1 addition & 0 deletions src/libs/shared/lib/contexts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './config.context'
1 change: 1 addition & 0 deletions src/libs/shared/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './contexts'
export * from './components'
export * from './containers'
export * from './hooks'
Expand Down