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 React from 'react';
|
||||
|
||||
import sessionsService from './services/functions/sessionsService'
|
||||
|
||||
setupIonicReact();
|
||||
|
||||
const routes = (
|
||||
@@ -67,27 +65,12 @@ const user: IUserManager = {
|
||||
export const UserContext = React.createContext<IUserManager>(user);
|
||||
|
||||
const IonicApp: React.FC = () => {
|
||||
|
||||
const [isLoggedIn, setIsLoggedIn] = useState(false);
|
||||
const user = useContext(UserContext);
|
||||
|
||||
user.setIsLoggedIn = setIsLoggedIn;
|
||||
|
||||
useEffect(() => {
|
||||
const verifyAuthenticatedUser = async () => {
|
||||
const refreshSessionRes = await sessionsService.refreshSession()
|
||||
|
||||
if (refreshSessionRes.error) {
|
||||
return
|
||||
}
|
||||
|
||||
if (refreshSessionRes.userId) {
|
||||
setIsLoggedIn(true)
|
||||
}
|
||||
}
|
||||
|
||||
verifyAuthenticatedUser()
|
||||
})
|
||||
|
||||
return(
|
||||
<IonApp>
|
||||
<IonReactRouter>
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
IonToolbar,
|
||||
} from "@ionic/react";
|
||||
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 './Perfil.css'
|
||||
@@ -25,8 +25,11 @@ import LocalStorage from "../LocalStorage";
|
||||
|
||||
import sessionsService from '../services/functions/sessionsService'
|
||||
import usersService from '../services/functions/usersService'
|
||||
import { UserContext } from "../App";
|
||||
|
||||
const Perfil: React.FC = () => {
|
||||
const user = useContext(UserContext);
|
||||
|
||||
const [showToast, setShowToast] = useState(false);
|
||||
const [messageToast, setMessageToast] = useState('');
|
||||
|
||||
@@ -52,6 +55,7 @@ const Perfil: React.FC = () => {
|
||||
|
||||
const logoff = () => {
|
||||
LocalStorage.clearToken()
|
||||
user.setIsLoggedIn(false);
|
||||
history.push('/login')
|
||||
}
|
||||
|
||||
@@ -108,7 +112,6 @@ const Perfil: React.FC = () => {
|
||||
|
||||
return () => { isMounted = false };
|
||||
}, []);
|
||||
// }, [history]);
|
||||
|
||||
return (
|
||||
<IonPage>
|
||||
|
||||
Reference in New Issue
Block a user