recover password feature

This commit is contained in:
2026-05-26 11:36:09 +01:00
parent b427fb0f85
commit b48f7783c9
12 changed files with 527 additions and 97 deletions

View File

@@ -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),