chore: fix notif
This commit is contained in:
@@ -28,7 +28,8 @@
|
|||||||
"android.permission.ACCESS_COARSE_LOCATION",
|
"android.permission.ACCESS_COARSE_LOCATION",
|
||||||
"android.permission.ACCESS_FINE_LOCATION",
|
"android.permission.ACCESS_FINE_LOCATION",
|
||||||
"android.permission.RECEIVE_BOOT_COMPLETED",
|
"android.permission.RECEIVE_BOOT_COMPLETED",
|
||||||
"android.permission.VIBRATE"
|
"android.permission.VIBRATE",
|
||||||
|
"android.permission.POST_NOTIFICATIONS"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"web": {
|
"web": {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { createContext, useContext, useState, useEffect, useRef, type ReactNode } from 'react';
|
import React, { createContext, useContext, useState, useEffect, type ReactNode } from 'react';
|
||||||
import {
|
import {
|
||||||
getToken, setToken as storeToken, removeToken,
|
getToken, setToken as storeToken, removeToken,
|
||||||
getAdminToken, setAdminToken as storeAdminToken, removeAdminToken,
|
getAdminToken, setAdminToken as storeAdminToken, removeAdminToken,
|
||||||
@@ -8,12 +8,7 @@ import {
|
|||||||
clearAllAuth,
|
clearAllAuth,
|
||||||
} from './tokenStorage';
|
} from './tokenStorage';
|
||||||
import { extractUsernameFromToken, extractRoleFromToken, isTokenExpired } from './jwtUtils';
|
import { extractUsernameFromToken, extractRoleFromToken, isTokenExpired } from './jwtUtils';
|
||||||
import {
|
import { removePushTokenFromBackend } from '../services/pushNotifications';
|
||||||
setupNotificationChannel,
|
|
||||||
registerForPushNotificationsAsync,
|
|
||||||
sendPushTokenToBackend,
|
|
||||||
removePushTokenFromBackend,
|
|
||||||
} from '../services/pushNotifications';
|
|
||||||
|
|
||||||
export type UserRole = 'client' | 'admin' | 'cabine' | 'livreur' | null;
|
export type UserRole = 'client' | 'admin' | 'cabine' | 'livreur' | null;
|
||||||
|
|
||||||
@@ -36,7 +31,6 @@ interface AuthContextType extends AuthState {
|
|||||||
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
||||||
|
|
||||||
export function AuthProvider({ children }: { children: ReactNode }) {
|
export function AuthProvider({ children }: { children: ReactNode }) {
|
||||||
const pushTokenRef = useRef<string | null>(null);
|
|
||||||
const [state, setState] = useState<AuthState>({
|
const [state, setState] = useState<AuthState>({
|
||||||
token: null,
|
token: null,
|
||||||
username: null,
|
username: null,
|
||||||
@@ -121,15 +115,6 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||||||
isAuthenticated: true,
|
isAuthenticated: true,
|
||||||
mustChangePassword,
|
mustChangePassword,
|
||||||
});
|
});
|
||||||
// Enregistrer le push token en arrière-plan
|
|
||||||
setupNotificationChannel().then(() =>
|
|
||||||
registerForPushNotificationsAsync()
|
|
||||||
).then((pushToken) => {
|
|
||||||
if (pushToken) {
|
|
||||||
pushTokenRef.current = pushToken;
|
|
||||||
sendPushTokenToBackend(pushToken);
|
|
||||||
}
|
|
||||||
}).catch(() => {/* silencieux */});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const setMustChangePassword = (value: boolean) => {
|
const setMustChangePassword = (value: boolean) => {
|
||||||
@@ -154,7 +139,6 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||||||
const logout = async () => {
|
const logout = async () => {
|
||||||
// Supprimer le push token du backend avant de se déconnecter
|
// Supprimer le push token du backend avant de se déconnecter
|
||||||
try { await removePushTokenFromBackend(); } catch { /* silencieux */ }
|
try { await removePushTokenFromBackend(); } catch { /* silencieux */ }
|
||||||
pushTokenRef.current = null;
|
|
||||||
await clearAllAuth();
|
await clearAllAuth();
|
||||||
setState({
|
setState({
|
||||||
token: null,
|
token: null,
|
||||||
|
|||||||
Reference in New Issue
Block a user