Skip to content

Commit

Permalink
chore: work continues on authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
Franqsanz committed Jan 5, 2024
1 parent eeb033e commit 3dc3d4a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/components/nav/menu/MenuProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ export function MenuProfile({ displayName, photoURL, uid }: MenuType) {
fontWeight='normal'
borderRadius='0'
justifyContent='left'
onClick={() => {
logOut();
navigate('/', { replace: true });
onClick={async () => {
await logOut();
navigate('/login', { replace: true });
}}
>
Cerrar Sessión
Expand Down
2 changes: 1 addition & 1 deletion src/pages/profile/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import ResultLength from '../../components/ResultLength';

export default function Profile() {
const { userId } = useParams();
const getToken = localStorage.getItem('app_tk');
const getToken = window.localStorage.getItem('app_tk');
const { data } = useProfile(userId, getToken);
const bgCover = useColorModeValue('gray.100', 'gray.700');

Expand Down
6 changes: 3 additions & 3 deletions src/services/firebase/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ function SignIn() {
async function signInWithGoogle() {
try {
const result = await signInWithPopup(logIn, provider);
const token = await result.user.getIdToken();
await localStorage.setItem('app_tk', token);
const token = await result.user.getIdToken(true);
await window.localStorage.setItem('app_tk', token);

return mutateAsync(token);
} catch (error) {
Expand Down Expand Up @@ -73,7 +73,7 @@ function SignIn() {
async function logOut() {
try {
await signOut(logIn);
await localStorage.removeItem('app_tk');
await window.localStorage.removeItem('app_tk');
} catch (error) {
console.error('Error al cerrar sesión:', error);
}
Expand Down
12 changes: 11 additions & 1 deletion src/store/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,19 @@ function AuthProvider({ children }: AuthProviderType) {
const auth = getAuth();

useEffect(() => {
const unsubscribe = onAuthStateChanged(auth, (user) => {
const unsubscribe = onAuthStateChanged(auth, async (user) => {
setCurrentUser(user);
setLoading(false);

// Renovación del token
if (user) {
try {
const token = await user.getIdToken(true);
window.localStorage.setItem('app_tk', token);
} catch (error) {
console.error('Error en app_tk:', error);
}
}
});

return () => unsubscribe();
Expand Down

1 comment on commit 3dc3d4a

@vercel
Copy link

@vercel vercel bot commented on 3dc3d4a Jan 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

xbu – ./

xbu.vercel.app
xbu-git-main-franqsanz.vercel.app
xbu-franqsanz.vercel.app

Please sign in to comment.