fixed push notifications and auth modified
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import React, { createContext, useContext, useEffect, useState } from "react";
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import Toast from "react-native-toast-message";
|
||||
import {
|
||||
authApi,
|
||||
|
||||
LoginPayload, RegisterPayload, subscriptionsApi, userApi, UserUpdateDTO,
|
||||
LoginPayload, RegisterPayload, setUnauthorizedHandler, subscriptionsApi, userApi, UserUpdateDTO,
|
||||
} from "@/services/api";
|
||||
|
||||
type User = {
|
||||
@@ -45,6 +46,20 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
setUser(u);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
setUnauthorizedHandler(() => {
|
||||
persist(null);
|
||||
Toast.show({
|
||||
type: 'info',
|
||||
text1: 'Session expired',
|
||||
text2: 'Please sign in again.',
|
||||
position: 'top',
|
||||
visibilityTime: 4000,
|
||||
});
|
||||
});
|
||||
return () => setUnauthorizedHandler(null);
|
||||
}, []);
|
||||
|
||||
const updateNotificationType = async (type: 'PUSH_NOTIFICATION' | 'NO_NOTIFICATION') => {
|
||||
if (!user) return;
|
||||
await userApi.updateNotificationType(type, user.token);
|
||||
|
||||
Reference in New Issue
Block a user