Fix duplicate /api/auth/member call and add request deduplication
Remove redundant checkMemberStatus() from coming-soon page since the auth-init plugin already handles it. Add in-flight request deduplication to prevent concurrent calls from any source. Strip debug console.logs.
This commit is contained in:
parent
52bb17e25d
commit
78c592c13a
3 changed files with 22 additions and 40 deletions
|
|
@ -1,3 +1,5 @@
|
|||
let pendingRequest = null;
|
||||
|
||||
export const useAuth = () => {
|
||||
const memberData = useState("auth.member", () => null);
|
||||
|
||||
|
|
@ -6,29 +8,24 @@ export const useAuth = () => {
|
|||
const isMember = computed(() => !!memberData.value);
|
||||
|
||||
const checkMemberStatus = async () => {
|
||||
console.log("🔍 checkMemberStatus called");
|
||||
console.log(" - Current memberData:", !!memberData.value);
|
||||
|
||||
try {
|
||||
console.log(" - Making API call to /api/auth/member...");
|
||||
const response = await $fetch("/api/auth/member");
|
||||
console.log(" - API response received:", {
|
||||
email: response.email,
|
||||
id: response.id,
|
||||
});
|
||||
memberData.value = response;
|
||||
console.log(" - ✅ Member authenticated successfully");
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error(
|
||||
" - ❌ Failed to fetch member status:",
|
||||
error.statusCode,
|
||||
error.statusMessage,
|
||||
);
|
||||
memberData.value = null;
|
||||
console.log(" - Cleared memberData");
|
||||
return false;
|
||||
if (pendingRequest) {
|
||||
return pendingRequest;
|
||||
}
|
||||
|
||||
pendingRequest = (async () => {
|
||||
try {
|
||||
const response = await $fetch("/api/auth/member");
|
||||
memberData.value = response;
|
||||
return true;
|
||||
} catch (error) {
|
||||
memberData.value = null;
|
||||
return false;
|
||||
} finally {
|
||||
pendingRequest = null;
|
||||
}
|
||||
})();
|
||||
|
||||
return pendingRequest;
|
||||
};
|
||||
|
||||
const logout = async () => {
|
||||
|
|
|
|||
|
|
@ -91,8 +91,6 @@ const loginError = ref("");
|
|||
|
||||
const isFormValid = computed(() => email.value && email.value.includes("@"));
|
||||
|
||||
await checkMemberStatus();
|
||||
|
||||
const handleLogin = async () => {
|
||||
if (isLoggingIn.value) return;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,7 @@
|
|||
export default defineNuxtPlugin(async () => {
|
||||
const { memberData, checkMemberStatus } = useAuth()
|
||||
|
||||
console.log('🚀 Auth init plugin running on CLIENT')
|
||||
|
||||
// Only initialize if we don't already have member data
|
||||
|
||||
if (!memberData.value) {
|
||||
console.log(' - No member data, checking auth status...')
|
||||
|
||||
const isAuthenticated = await checkMemberStatus()
|
||||
|
||||
if (isAuthenticated) {
|
||||
console.log(' - ✅ Authentication successful')
|
||||
} else {
|
||||
console.log(' - ❌ No valid authentication')
|
||||
}
|
||||
} else {
|
||||
console.log(' - ✅ Member data already exists:', memberData.value.email)
|
||||
await checkMemberStatus()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue