feat: clear local authentication token when switching from local auth mode

This commit is contained in:
Abhimanyu Saharan
2026-02-11 19:36:44 +05:30
parent 571b4844d9
commit 1a35fa1f21

View File

@@ -1,14 +1,26 @@
"use client"; "use client";
import { ClerkProvider } from "@clerk/nextjs"; import { ClerkProvider } from "@clerk/nextjs";
import type { ReactNode } from "react"; import { useEffect, type ReactNode } from "react";
import { isLikelyValidClerkPublishableKey } from "@/auth/clerkKey"; import { isLikelyValidClerkPublishableKey } from "@/auth/clerkKey";
import { getLocalAuthToken, isLocalAuthMode } from "@/auth/localAuth"; import {
clearLocalAuthToken,
getLocalAuthToken,
isLocalAuthMode,
} from "@/auth/localAuth";
import { LocalAuthLogin } from "@/components/organisms/LocalAuthLogin"; import { LocalAuthLogin } from "@/components/organisms/LocalAuthLogin";
export function AuthProvider({ children }: { children: ReactNode }) { export function AuthProvider({ children }: { children: ReactNode }) {
if (isLocalAuthMode()) { const localMode = isLocalAuthMode();
useEffect(() => {
if (!localMode) {
clearLocalAuthToken();
}
}, [localMode]);
if (localMode) {
if (!getLocalAuthToken()) { if (!getLocalAuthToken()) {
return <LocalAuthLogin />; return <LocalAuthLogin />;
} }