Saving API key on startup and fixed various deprecated messages

This commit is contained in:
2025-10-15 10:00:23 +02:00
parent f10d8d0777
commit 8895bc9c9d
6 changed files with 59 additions and 69 deletions

View File

@@ -4,8 +4,7 @@ import { useEffect, useState } from "react";
import { Platform } from "react-native";
type RegisterTokenParams = {
userId: number;
apiKey: string;
apiKey?: string | null;
backendUrl: string;
appVersion?: string;
locale?: string;
@@ -13,16 +12,16 @@ type RegisterTokenParams = {
};
export function usePushNotifications({
userId,
apiKey,
backendUrl,
appVersion = "1.0.0",
locale,
topics
}: RegisterTokenParams) {
}: RegisterTokenParams & { apiKey?: string | null }) {
const [expoPushToken, setExpoPushToken] = useState<string | null>(null);
useEffect(() => {
if (!apiKey) return;
(async () => {
const token = await registerForPushNotificationsAsync();
if (token) {
@@ -30,7 +29,7 @@ export function usePushNotifications({
await registerTokenWithBackend(token);
}
})();
}, []);
}, [apiKey]);
const registerTokenWithBackend = async (token: string) => {
try {
@@ -38,10 +37,9 @@ export function usePushNotifications({
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": apiKey
"X-API-Key": apiKey ?? "",
},
body: JSON.stringify({
user_id: userId,
token,
platform: Platform.OS,
app_ver: appVersion,