diff --git a/src/components/giving/Giving.astro b/src/components/giving/Giving.astro index cf0ac5e..ae5c4de 100644 --- a/src/components/giving/Giving.astro +++ b/src/components/giving/Giving.astro @@ -1,10 +1,11 @@ --- +export const prerender = false; import GivingForm from './GivingForm.astro'; import NotSubbed from './NotSubbed.astro'; import Registered from './Registered.astro'; import SignIn from './SignIn.astro'; import { getSub } from '@lib/supabase'; -import { isSub } from '@scripts/twitch'; +import { subCheck } from '@scripts/twitch'; export interface Props { user: { @@ -15,7 +16,7 @@ export interface Props { }; } const { user } = Astro.props; -const isSubscriber = user ? await isSub(user.user_id) : null; +const check = user ? await subCheck(user.user_id) : null; const registered = user ? await getSub(user.id) : null; --- @@ -26,10 +27,11 @@ const registered = user ? await getSub(user.id) : null; {!user && } - {user && !isSubscriber && + {user && !check?.isSub && + } - {user && isSubscriber && !registered && + {user && check?.isSub && !registered && } {user && registered && diff --git a/src/components/giving/GivingForm.astro b/src/components/giving/GivingForm.astro index 311bac6..ff22693 100644 --- a/src/components/giving/GivingForm.astro +++ b/src/components/giving/GivingForm.astro @@ -1,5 +1,4 @@ --- - export interface Props { user: { id: string; diff --git a/src/components/giving/NotSubbed.astro b/src/components/giving/NotSubbed.astro index 4f64454..0337b9d 100644 --- a/src/components/giving/NotSubbed.astro +++ b/src/components/giving/NotSubbed.astro @@ -1,5 +1,4 @@ --- - export interface Props { user: { id: string; diff --git a/src/components/giving/SignIn.astro b/src/components/giving/SignIn.astro index 3f90fce..7af4af8 100644 --- a/src/components/giving/SignIn.astro +++ b/src/components/giving/SignIn.astro @@ -1,14 +1,5 @@ --- import Icon from "@components/Icon.astro" -export interface Props { - user: { - id: string; - nickname: string; - profileImg: string; - }; -} -const { user } = Astro.props; - ---

Get in on the fun!

diff --git a/src/pages/notyou.astro b/src/pages/notyou.astro index f3c40f0..c13278e 100644 --- a/src/pages/notyou.astro +++ b/src/pages/notyou.astro @@ -9,9 +9,6 @@ const permalink = `https://${import.meta.env.HOST}/`; const user = await authData(Astro.cookies); -if (user && user.nickname.toLowerCase() === "cmjchrisjones") { - Astro.redi -} --- diff --git a/src/pages/register.astro b/src/pages/register.astro deleted file mode 100644 index ebc0636..0000000 --- a/src/pages/register.astro +++ /dev/null @@ -1,13 +0,0 @@ ---- -export const prerender = false; ---- - -

Register

-

Already have an account? Sign in

-
- - - - - -
diff --git a/src/pages/signin.astro b/src/pages/signin.astro deleted file mode 100644 index 7deebc6..0000000 --- a/src/pages/signin.astro +++ /dev/null @@ -1,15 +0,0 @@ ---- -export const prerender = false; -const { cookies, redirect } = Astro; - -const accessToken = cookies.get("sb-access-token"); -const refreshToken = cookies.get("sb-refresh-token"); - -if (accessToken && refreshToken) { - return redirect("/giving/"); -} ---- - -

Sign in

- - Sign in diff --git a/src/scripts/twitch.ts b/src/scripts/twitch.ts index 6b4a17c..e2fd588 100644 --- a/src/scripts/twitch.ts +++ b/src/scripts/twitch.ts @@ -86,7 +86,7 @@ export async function isOnline(): Promise { return thumbnail; } -export async function isSub(userId: string): Promise { +export async function subCheck(userId: string): Promise<{isSub: boolean, err: any}> { const headers = await getATHeaders(); const response = await fetch( `https://api.twitch.tv/helix/subscriptions?broadcaster_id=${import.meta.env.TWITCH_CHANNEL_ID}&user_id=${userId}`, @@ -94,12 +94,20 @@ export async function isSub(userId: string): Promise { headers, }, ); + + const body = await response.text(); const { data: subscribers } = JSON.parse(body); if (subscribers && subscribers.length > 0) { - return true; + return { + isSub: true, + err: null + }; } - return false; + return { + isSub: false, + err: {status: response.status, message: response.statusText} + }; }