migrate auth v2 code
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
import { formatDDMMYY, formatHumanDate } from '$lib/format';
|
||||
import { ViewHeader, CardGrid, Card, Button } from '$lib/components';
|
||||
import type { AssignedChore, Completion, ChoreTemplate, BonusConfig, Reward } from '$lib/types';
|
||||
import { handleOf } from '@shared/slugify';
|
||||
import {
|
||||
weekStart as tzWeekStart,
|
||||
addDaysStr,
|
||||
@@ -149,7 +150,7 @@
|
||||
|
||||
// ─── Child View (kanban) ───
|
||||
let memberId = $state(data.memberId || '');
|
||||
let deviceToken = $state(data.token || '');
|
||||
let pbToken = $state(data.token || '');
|
||||
let famId = $state(data.famId || '');
|
||||
let memberName = $state(data.memberName || '');
|
||||
let memberColor = $state(data.memberColor || '#6366f1');
|
||||
@@ -209,9 +210,9 @@
|
||||
$effect(() => {
|
||||
if (role !== 'child' || !isPaydayToday) return;
|
||||
if (secondsLeft > 0 || eowFired) return;
|
||||
if (!deviceToken || !famId) return;
|
||||
if (!pbToken || !famId) return;
|
||||
eowFired = true;
|
||||
memberApi.payday(deviceToken, famId).catch(() => {});
|
||||
memberApi.payday(pbToken, famId).catch(() => {});
|
||||
});
|
||||
|
||||
function paydayWeekStart(): string {
|
||||
@@ -476,26 +477,13 @@
|
||||
onMount(async () => {
|
||||
if (role === 'parent') return;
|
||||
|
||||
if (!deviceToken) {
|
||||
deviceToken = localStorage.getItem('deviceToken') || '';
|
||||
} else {
|
||||
localStorage.setItem('deviceToken', deviceToken);
|
||||
}
|
||||
|
||||
if (!deviceToken) {
|
||||
error = 'No device token found. Use the link from your invite.';
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.verified && data.famId && data.memberId) {
|
||||
memberId = data.memberId;
|
||||
famId = data.famId;
|
||||
loading = false;
|
||||
} else {
|
||||
error = 'Invalid device token. Use the link from your invite.';
|
||||
error = 'Please open your invite link to get access.';
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -558,7 +546,7 @@
|
||||
}
|
||||
|
||||
try {
|
||||
await memberApi.toggleCompletion(deviceToken, famId, chore.id, todayChild);
|
||||
await memberApi.toggleCompletion(pbToken, famId, chore.id, todayChild);
|
||||
const optimistic = completions.find((c) => c.id === 'optimistic-' + chore.id);
|
||||
if (optimistic) {
|
||||
famStore.applyRecord('completions', optimistic, 'delete');
|
||||
@@ -644,7 +632,7 @@
|
||||
<div class="card-header">
|
||||
<span class="dot" style="background:{m.color}"></span>
|
||||
<span class="member-name">{m.name}</span>
|
||||
<a href="/{famSlug}/{m.name}" class="link">Kanban</a>
|
||||
<a href="/{famSlug}/{handleOf(m.username)}" class="link">Kanban</a>
|
||||
</div>
|
||||
<div class="stats">
|
||||
<span>Points: {s?.pointsEarned ?? 0}</span>
|
||||
@@ -976,8 +964,7 @@
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'x-device-token': deviceToken,
|
||||
'x-device-famid': famId
|
||||
Authorization: `Bearer ${pbToken}`
|
||||
},
|
||||
body: JSON.stringify({ name: nameInput })
|
||||
});
|
||||
@@ -1039,8 +1026,7 @@
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'x-device-token': deviceToken,
|
||||
'x-device-famid': famId
|
||||
Authorization: `Bearer ${pbToken}`
|
||||
},
|
||||
body: JSON.stringify({ color })
|
||||
});
|
||||
@@ -1267,7 +1253,7 @@
|
||||
class="wr-cta"
|
||||
onclick={async () => {
|
||||
try {
|
||||
await memberApi.claimReward(deviceToken, famId, r.id);
|
||||
await memberApi.claimReward(pbToken, famId, r.id);
|
||||
} catch (e) {
|
||||
claimError = e instanceof Error ? e.message : 'Claim failed';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user