eletrotupi / tcc/ commit / 32f2f03

frontend: nuke mmkv persisted cache + query cache on logout

Pedro Lucas Porcellis porcellis@eletrotupi.com · 5 months ago 32f2f039f05dad64bc0e752c2b571e606c991d7e Browse files
Parents 5f5ade6
Changed files
1
Additions
+5
Deletions
0
frontend/context/AuthContext.tsx
1 1
import React, { createContext, useContext, useEffect, useState } from 'react';
2 2
import { apiClient, User } from '@/lib/api';
3 +
import { queryClient, storage } from '@/lib/queryClient';
3 4

4 5
interface AuthProviderProps {
5 6
  children: React.ReactNode;
6 7
}
7 8

119 120

120 121
  const logout = async () => {
121 122
    setIsLoading(true);
122 123
    try {
123 124
      await apiClient.logout();
125 +

124 126
      setUser(null);
127 +
      // Clear both the in-memory cache and the persisted MMKV cache
128 +
      queryClient.clear();
129 +
      storage.clearAll();
125 130
    } finally {
126 131
      setIsLoading(false);
127 132
    }
128 133
  };
129 134

155 160
    <AuthContext.Provider value={value}>
156 161
      {children}
157 162
    </AuthContext.Provider>
158 163
  );
159 164
}