fix: don't show login prompt if token is defined in state

Signed-off-by: Ali Dalal <ali.dalal@bonial.com>
This commit is contained in:
Ali Dalal
2024-03-27 16:58:47 +01:00
parent 8cc47df993
commit 419e948d42
6 changed files with 103 additions and 7 deletions
@@ -35,4 +35,20 @@ describe('SecretsContext', () => {
expect(result.current.hook?.secrets.foo).toEqual('bar');
});
it('should create SecretsContextProvider with initial secrets', async () => {
const { result } = renderHook(
() => ({
hook: useTemplateSecrets(),
}),
{
wrapper: ({ children }: React.PropsWithChildren<{}>) => (
<SecretsContextProvider initialSecrets={{ foo: 'bar' }}>
{children}
</SecretsContextProvider>
),
},
);
expect(result.current.hook?.secrets.foo).toEqual('bar');
});
});
@@ -43,8 +43,13 @@ const SecretsContext = createVersionedContext<{
* The Context Provider that holds the state for the secrets.
* @public
*/
export const SecretsContextProvider = (props: PropsWithChildren<{}>) => {
const [secrets, setSecrets] = useState<Record<string, string>>({});
export const SecretsContextProvider = (
props: PropsWithChildren<{ initialSecrets?: Record<string, string> }>,
) => {
const { initialSecrets = {} } = props;
const [secrets, setSecrets] = useState<Record<string, string>>({
...initialSecrets,
});
return (
<SecretsContext.Provider