aboutsummaryrefslogtreecommitdiff
path: root/src/routes/authentication/AuthProvider.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes/authentication/AuthProvider.tsx')
-rw-r--r--src/routes/authentication/AuthProvider.tsx27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/routes/authentication/AuthProvider.tsx b/src/routes/authentication/AuthProvider.tsx
index 55a6f3ad..383b4d5b 100644
--- a/src/routes/authentication/AuthProvider.tsx
+++ b/src/routes/authentication/AuthProvider.tsx
@@ -4,19 +4,19 @@ import {INTEGRATED_SOCIAL_LIST} from '../../constants';
import {
loadAvatar,
loadCover,
+ loadFollowers,
+ loadFollowing,
+ loadMoments,
loadProfileInfo,
loadRecentlySearchedUsers,
loadSocialPosts,
- loadMoments,
- loadFollowers,
- loadFollowing,
} from '../../services';
import {
+ MomentType,
ProfilePreviewType,
ProfileType,
SocialAccountType,
UserType,
- MomentType,
} from '../../types';
interface AuthContextProps {
@@ -98,6 +98,23 @@ const AuthProvider: React.FC = ({children}) => {
const [following, setFollowing] = useState<Array<ProfilePreviewType>>([]);
const [followersNeedUpdate, setFollowersNeedUpdate] = useState<boolean>(true);
const {userId} = user;
+
+ useEffect(() => {
+ const loadUserInfoFromStorage = async () => {
+ const [id, username, token] = await Promise.all([
+ AsyncStorage.getItem('userId'),
+ AsyncStorage.getItem('username'),
+ AsyncStorage.getItem('token'),
+ ]);
+ if (id && username && token) {
+ setUser({...user, userId: id, username});
+ }
+ };
+ if (user === NO_USER) {
+ loadUserInfoFromStorage();
+ }
+ }, [user]);
+
useEffect(() => {
if (!userId) {
return;
@@ -196,6 +213,8 @@ const AuthProvider: React.FC = ({children}) => {
try {
new Promise(() => {
AsyncStorage.removeItem('token');
+ AsyncStorage.removeItem('userId');
+ AsyncStorage.removeItem('username');
}).then(() => {
setUser(NO_USER);
});