Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'beta' into split-config
- Loading branch information
Showing
9 changed files
with
152 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as ConfigProvider, ConfigProviderProps, useConfig } from './use-config'; | ||
export { default as UserProvider, UserProviderProps, UserProfile, UserContext, useUser } from './use-user'; | ||
export { default as withPageAuthRequired, WithPageAuthRequired } from './with-page-auth-required'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React, { ReactElement, useContext, createContext } from 'react'; | ||
|
||
export type ConfigContext = { | ||
loginUrl?: string; | ||
}; | ||
|
||
const Config = createContext<ConfigContext>({}); | ||
|
||
export type ConfigProviderProps = React.PropsWithChildren<ConfigContext>; | ||
export type UseConfig = () => ConfigContext; | ||
export const useConfig: UseConfig = () => useContext<ConfigContext>(Config); | ||
|
||
export default ({ | ||
children, | ||
loginUrl = process.env.NEXT_PUBLIC_AUTH0_LOGIN || '/api/auth/login' | ||
}: ConfigProviderProps): ReactElement<ConfigContext> => { | ||
return <Config.Provider value={{ loginUrl }}>{children}</Config.Provider>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
|
||
import { withConfigProvider } from '../fixtures/frontend'; | ||
import { useConfig } from '../../src/frontend/use-config'; | ||
|
||
jest.mock('next/router', () => ({ | ||
useRouter: (): any => ({ asPath: '/' }) | ||
})); | ||
|
||
describe('context wrapper', () => { | ||
test('should provide the default login url', async () => { | ||
const { result } = renderHook(() => useConfig(), { | ||
wrapper: withConfigProvider({ loginUrl: '/api/auth/login' }) | ||
}); | ||
|
||
expect(result.current.loginUrl).toEqual('/api/auth/login'); | ||
}); | ||
|
||
test('should provide a custom login url', async () => { | ||
const { result } = renderHook(() => useConfig(), { | ||
wrapper: withConfigProvider({ loginUrl: '/api/custom-url' }) | ||
}); | ||
|
||
expect(result.current.loginUrl).toEqual('/api/custom-url'); | ||
}); | ||
|
||
test('should provide a custom login url from an environment variable', async () => { | ||
process.env.NEXT_PUBLIC_AUTH0_LOGIN = '/api/custom-url'; | ||
const { result } = renderHook(() => useConfig(), { | ||
wrapper: withConfigProvider() | ||
}); | ||
|
||
expect(result.current.loginUrl).toEqual('/api/custom-url'); | ||
delete process.env.NEXT_PUBLIC_AUTH0_LOGIN; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters