recover password feature
This commit is contained in:
@@ -2,6 +2,8 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import CryptoJS from 'crypto-js';
|
||||
import { createContext, useContext, useEffect, useState } from 'react';
|
||||
import { API_CONFIG, API_ENDPOINTS, buildApiUrl } from '../config/api';
|
||||
import { clearDownloadedDocuments } from '../services/documentSync';
|
||||
import { clearUserSessionCache } from '../services/offlineStorage';
|
||||
import { AuthContextType, AuthProviderProps, LoginResponse, User, UserData } from '../types';
|
||||
// Contexto
|
||||
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
||||
@@ -74,6 +76,10 @@ export function AuthProvider({ children }: AuthProviderProps) {
|
||||
throw new Error(data.message || 'Erro ao fazer login');
|
||||
}
|
||||
|
||||
// Limpar dados do utilizador anterior antes de guardar a nova sessão
|
||||
await clearUserSessionCache();
|
||||
await clearDownloadedDocuments();
|
||||
|
||||
// Se a resposta for bem-sucedida, Guardar token e user
|
||||
if (data.token) {
|
||||
setToken(data.token);
|
||||
@@ -186,7 +192,10 @@ export function AuthProvider({ children }: AuthProviderProps) {
|
||||
setToken(null);
|
||||
setError(null);
|
||||
|
||||
// Limpar AsyncStorage
|
||||
await clearUserSessionCache();
|
||||
await clearDownloadedDocuments();
|
||||
|
||||
// Limpar credenciais de sessão
|
||||
await Promise.all([
|
||||
AsyncStorage.removeItem(STORAGE_KEYS.TOKEN),
|
||||
AsyncStorage.removeItem(STORAGE_KEYS.USER),
|
||||
|
||||
Reference in New Issue
Block a user