Skip to content

Commit

Permalink
Auth: Prevent /start calls when logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
jmderby committed Feb 14, 2025
1 parent d31f5c8 commit 9eeed22
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export function CrossmintAuthProvider({
appearance={appearance}
>
<AuthFormProvider
preFetchOAuthUrls={getAuthStatus() === "logged-out"}
initialState={{
appearance,
setDialogOpen,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ type ContextInitialStateProps = {
embeddedWallets: CrossmintAuthWalletConfig;
};

type AuthFormProviderProps = {
preFetchOAuthUrls: boolean;
initialState: ContextInitialStateProps;
children: ReactNode;
};

const AuthFormContext = createContext<AuthFormContextType | undefined>(undefined);

export const useAuthForm = () => {
Expand All @@ -47,10 +53,7 @@ export const useAuthForm = () => {
return context;
};

export const AuthFormProvider = ({
children,
initialState,
}: { children: ReactNode; initialState: ContextInitialStateProps }) => {
export const AuthFormProvider = ({ preFetchOAuthUrls, initialState, children }: AuthFormProviderProps) => {
const { crossmintAuth } = useCrossmintAuth();
const [step, setStep] = useState<AuthStep>("initial");
const [error, setError] = useState<string | null>(null);
Expand Down Expand Up @@ -90,8 +93,11 @@ export const AuthFormProvider = ({
}, [loginMethods, crossmintAuth]);

useEffect(() => {
preFetchAndSetOauthUrl();
}, [preFetchAndSetOauthUrl]);
// Only pre-fetch oauth urls if the user is not logged in
if (preFetchOAuthUrls) {
preFetchAndSetOauthUrl();
}
}, [preFetchAndSetOauthUrl, preFetchOAuthUrls]);

const handleToggleDialog = (open: boolean) => {
setDialogOpen?.(open);
Expand Down

0 comments on commit 9eeed22

Please sign in to comment.