-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathnotification-registration.ts
More file actions
43 lines (37 loc) · 1.08 KB
/
Copy pathnotification-registration.ts
File metadata and controls
43 lines (37 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { apiClient } from "#app/lib/api-client"
import { tryCatch } from "#shared/lib/trycatch"
export { triggerNotificationRegistration }
type RegistrationResult = { ok: true } | { ok: false; error: string }
async function triggerNotificationRegistration(
notificationSettingsId: string,
authToken: string,
): Promise<RegistrationResult> {
let result = await tryCatch(
apiClient.push.register.$post(
{
json: { notificationSettingsId },
},
{
headers: {
Authorization: `Jazz ${authToken}`,
},
},
),
)
if (!result.ok) {
console.error("[Notifications] Registration failed:", result.error)
return { ok: false, error: "Network error" }
}
if (!result.data.ok) {
let errorData = await tryCatch(
result.data.json() as Promise<{ message?: string }>,
)
let errorMessage = errorData.ok
? errorData.data.message || "Unknown error"
: "Unknown error"
console.error("[Notifications] Registration error:", errorMessage)
return { ok: false, error: errorMessage }
}
console.log("[Notifications] Registration triggered successfully")
return { ok: true }
}