use session storage for client secret during onboarding (fix #14)
This commit is contained in:
23
apps/dashboard/src/hooks/useClientSecret.ts
Normal file
23
apps/dashboard/src/hooks/useClientSecret.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
export const ONBOARDING_SECRET_KEY = 'onboarding.clientSecret';
|
||||
const DEFAULT_SECRET = '[CLIENT_SECRET]';
|
||||
|
||||
export function useClientSecret() {
|
||||
const [clientSecret, setClientSecret] = useState<string>(DEFAULT_SECRET);
|
||||
|
||||
useEffect(() => {
|
||||
if (clientSecret && DEFAULT_SECRET !== clientSecret) {
|
||||
sessionStorage.setItem(ONBOARDING_SECRET_KEY, clientSecret);
|
||||
}
|
||||
}, [clientSecret]);
|
||||
|
||||
useEffect(() => {
|
||||
const clientSecret = sessionStorage.getItem(ONBOARDING_SECRET_KEY);
|
||||
if (clientSecret) {
|
||||
setClientSecret(clientSecret);
|
||||
}
|
||||
}, []);
|
||||
|
||||
return [clientSecret, setClientSecret] as const;
|
||||
}
|
||||
Reference in New Issue
Block a user