Tabbar some agora com logout
This commit is contained in:
19
src/App.tsx
19
src/App.tsx
@@ -40,8 +40,6 @@ import { search, home, person } from 'ionicons/icons';
|
|||||||
import { useState, useContext, useEffect } from 'react';
|
import { useState, useContext, useEffect } from 'react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import sessionsService from './services/functions/sessionsService'
|
|
||||||
|
|
||||||
setupIonicReact();
|
setupIonicReact();
|
||||||
|
|
||||||
const routes = (
|
const routes = (
|
||||||
@@ -67,27 +65,12 @@ const user: IUserManager = {
|
|||||||
export const UserContext = React.createContext<IUserManager>(user);
|
export const UserContext = React.createContext<IUserManager>(user);
|
||||||
|
|
||||||
const IonicApp: React.FC = () => {
|
const IonicApp: React.FC = () => {
|
||||||
|
|
||||||
const [isLoggedIn, setIsLoggedIn] = useState(false);
|
const [isLoggedIn, setIsLoggedIn] = useState(false);
|
||||||
const user = useContext(UserContext);
|
const user = useContext(UserContext);
|
||||||
|
|
||||||
user.setIsLoggedIn = setIsLoggedIn;
|
user.setIsLoggedIn = setIsLoggedIn;
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const verifyAuthenticatedUser = async () => {
|
|
||||||
const refreshSessionRes = await sessionsService.refreshSession()
|
|
||||||
|
|
||||||
if (refreshSessionRes.error) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (refreshSessionRes.userId) {
|
|
||||||
setIsLoggedIn(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
verifyAuthenticatedUser()
|
|
||||||
})
|
|
||||||
|
|
||||||
return(
|
return(
|
||||||
<IonApp>
|
<IonApp>
|
||||||
<IonReactRouter>
|
<IonReactRouter>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
IonToolbar,
|
IonToolbar,
|
||||||
} from "@ionic/react";
|
} from "@ionic/react";
|
||||||
import { useHistory } from "react-router-dom";
|
import { useHistory } from "react-router-dom";
|
||||||
import React, { useState, useEffect, useReducer } from "react";
|
import React, { useState, useEffect, useReducer, useContext } from "react";
|
||||||
import { cardOutline, carOutline, createOutline, exitOutline, shieldCheckmarkOutline, starOutline } from "ionicons/icons";
|
import { cardOutline, carOutline, createOutline, exitOutline, shieldCheckmarkOutline, starOutline } from "ionicons/icons";
|
||||||
|
|
||||||
import './Perfil.css'
|
import './Perfil.css'
|
||||||
@@ -25,8 +25,11 @@ import LocalStorage from "../LocalStorage";
|
|||||||
|
|
||||||
import sessionsService from '../services/functions/sessionsService'
|
import sessionsService from '../services/functions/sessionsService'
|
||||||
import usersService from '../services/functions/usersService'
|
import usersService from '../services/functions/usersService'
|
||||||
|
import { UserContext } from "../App";
|
||||||
|
|
||||||
const Perfil: React.FC = () => {
|
const Perfil: React.FC = () => {
|
||||||
|
const user = useContext(UserContext);
|
||||||
|
|
||||||
const [showToast, setShowToast] = useState(false);
|
const [showToast, setShowToast] = useState(false);
|
||||||
const [messageToast, setMessageToast] = useState('');
|
const [messageToast, setMessageToast] = useState('');
|
||||||
|
|
||||||
@@ -52,6 +55,7 @@ const Perfil: React.FC = () => {
|
|||||||
|
|
||||||
const logoff = () => {
|
const logoff = () => {
|
||||||
LocalStorage.clearToken()
|
LocalStorage.clearToken()
|
||||||
|
user.setIsLoggedIn(false);
|
||||||
history.push('/login')
|
history.push('/login')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +112,6 @@ const Perfil: React.FC = () => {
|
|||||||
|
|
||||||
return () => { isMounted = false };
|
return () => { isMounted = false };
|
||||||
}, []);
|
}, []);
|
||||||
// }, [history]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IonPage>
|
<IonPage>
|
||||||
|
|||||||
Reference in New Issue
Block a user