From f056a1e19470967198b1dab61cf6133047f07afd Mon Sep 17 00:00:00 2001 From: Fuwn Date: Fri, 15 Dec 2023 23:54:53 -0800 Subject: feat(notifications): refresh token --- src/routes/feeds/activity-notifications/+server.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/routes/feeds') diff --git a/src/routes/feeds/activity-notifications/+server.ts b/src/routes/feeds/activity-notifications/+server.ts index fde2027d..f0482194 100644 --- a/src/routes/feeds/activity-notifications/+server.ts +++ b/src/routes/feeds/activity-notifications/+server.ts @@ -59,9 +59,19 @@ const render = (posts: Notification[] = []) => ` { - const token = url.searchParams.get('token'); + let token = url.searchParams.get('token'); + const refresh = url.searchParams.get('refresh'); + let notification = await notifications(token || ''); - return new Response(token ? render(await notifications(token)) : render(), { + if (notification === null) { + token = ( + await (await fetch(`https://192.168.1.60:5173/api/oauth/refresh?token=${refresh}`)).json() + )['access_token']; + + notification = await notifications(token as string); + } + + return new Response(token ? render(notification || []) : render(), { headers: { 'Cache-Control': `max-age=0, s-max-age=0`, 'Content-Type': 'application/xml' -- cgit v1.2.3