Skip to content

Commit 1e25b1c

Browse files
authored
[LC-1467] - fix: Logout Behavior (#880)
* close all modals on logout * fix weird redirect on logout * potentially fix hard refresh * Create quick-mangos-peel.md
1 parent ba9b266 commit 1e25b1c

File tree

4 files changed

+42
-17
lines changed

4 files changed

+42
-17
lines changed

.changeset/quick-mangos-peel.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"learn-card-app": patch
3+
"learn-card-base": patch
4+
---
5+
6+
fix: Logout Behavior

apps/learn-card-app/src/components/learncard/MyLearnCardModal.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,9 @@ const MyLearnCardModal: React.FC<MyLearnCardModalProps> = ({
496496

497497
{!hideLogout && (
498498
<button
499-
onClick={() => handleLogout(branding)}
499+
onClick={() =>
500+
handleLogout(branding, { overrideRedirectUrl: '/login' })
501+
}
500502
className="flex items-center justify-center gap-[5px] py-[10px] text-grayscale-900 font-notoSans text-[20px] disabled:opacity-60"
501503
disabled={isLoggingOut}
502504
>

apps/learn-card-app/src/hooks/useLogout.tsx

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
1-
import React, { useEffect, useState } from 'react';
2-
import { FirebaseAuthentication } from '@capacitor-firebase/authentication';
1+
import { useState } from 'react';
32
import { Capacitor } from '@capacitor/core';
4-
import authStore from 'learn-card-base/stores/authStore';
5-
import { SocialLoginTypes } from 'learn-card-base/hooks/useSocialLogins';
6-
import { LOGIN_REDIRECTS } from 'learn-card-base/constants/redirects';
7-
import { BrandingEnum } from 'learn-card-base';
8-
import { pushUtilities } from 'learn-card-base';
3+
import { useHistory } from 'react-router-dom';
4+
import { FirebaseAuthentication } from '@capacitor-firebase/authentication';
5+
96
import { auth } from '../firebase/firebase';
10-
import { useWeb3AuthSFA, useWallet, useToast, ToastTypeEnum } from 'learn-card-base';
11-
import useSQLiteStorage from 'learn-card-base/hooks/useSQLiteStorage';
7+
import authStore from 'learn-card-base/stores/authStore';
8+
9+
import {
10+
useModal,
11+
BrandingEnum,
12+
pushUtilities,
13+
LOGIN_REDIRECTS,
14+
SocialLoginTypes,
15+
useWeb3AuthSFA,
16+
useToast,
17+
useWallet,
18+
ToastTypeEnum,
19+
useSQLiteStorage,
20+
} from 'learn-card-base';
1221
import { useQueryClient } from '@tanstack/react-query';
13-
import { IonLoading } from '@ionic/react';
1422

1523
const useLogout = () => {
16-
const [isLoggingOut, setIsLoggingOut] = useState<boolean>(false);
17-
const { logout, loggingOut: web3AuthLoggingOut } = useWeb3AuthSFA();
18-
const { clearDB } = useSQLiteStorage();
1924
const firebaseAuth = auth();
25+
const history = useHistory();
2026
const { initWallet } = useWallet();
21-
const { presentToast } = useToast();
2227
const queryClient = useQueryClient();
28+
const { clearDB } = useSQLiteStorage();
29+
const { logout, loggingOut: web3AuthLoggingOut } = useWeb3AuthSFA();
30+
31+
const { closeAllModals } = useModal();
32+
const { presentToast } = useToast();
33+
34+
const [isLoggingOut, setIsLoggingOut] = useState<boolean>(false);
2335

2436
const handleLogout = async (
2537
branding: BrandingEnum,
@@ -82,7 +94,12 @@ const useLogout = () => {
8294
console.error(e);
8395
}
8496

85-
await logout(redirectUrl);
97+
closeAllModals();
98+
99+
await logout();
100+
101+
// handle redirect from within LCA over web3Auth redirect
102+
history.push(redirectUrl);
86103
} catch (e) {
87104
console.error('There was an issue logging out', e);
88105
setIsLoggingOut(false);

packages/learn-card-base/src/hooks/useWeb3AuthSFA.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export const useWeb3AuthSFA = () => {
212212
};
213213

214214
const logout = async (
215-
redirectUrl: string = 'https://learncard.app/',
215+
redirectUrl?: string,
216216
_branding: BrandingEnum = BrandingEnum.learncard
217217
) => {
218218
try {

0 commit comments

Comments
 (0)