Skip to content

Commit

Permalink
Removing sub check
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljolley committed Dec 1, 2024
1 parent 3592b88 commit 478620d
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 119 deletions.
9 changes: 1 addition & 8 deletions src/components/giving/Giving.astro
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
---
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 { subCheck } from '@scripts/twitch';
export interface Props {
user: {
Expand All @@ -16,7 +14,6 @@ export interface Props {
};
}
const { user } = Astro.props;
const check = user ? await subCheck(user.user_id) : null;
const registered = user ? await getSub(user.id) : null;
---
Expand All @@ -27,11 +24,7 @@ const registered = user ? await getSub(user.id) : null;
{!user &&
<SignIn />
}
{user && !check?.isSub &&
<NotSubbed user={user} />
<!-- ({check.status} {check.message}) -->
}
{user && check?.isSub && !registered &&
{user && !registered &&
<GivingForm user={user} />
}
{user && registered &&
Expand Down
5 changes: 3 additions & 2 deletions src/components/giving/GivingForm.astro
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ const { user } = Astro.props;
{user.nickname}!
</h3>
<p>
We made a subscriber list, checked it twice, and you're on it! Register
below to receive your Season of Gifting gifts. 🎁
We're making a subscriber list and checking it twice, so make sure you're on
it by December 19th, 2024! And be sure to register below to receive your
Season of Gifting gifts. 🎁
</p>
<form
name="giving-register"
Expand Down
74 changes: 0 additions & 74 deletions src/components/giving/NotSubbed.astro

This file was deleted.

2 changes: 1 addition & 1 deletion src/pages/api/auth/signin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const GET: APIRoute = async ({ request, cookies, redirect }) => {
const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'twitch',
options: {
redirectTo: `https://baldbeardedbuilder.com/api/auth/callback/`
redirectTo: `https://baldbeardedbuilder.com/api/auth/callback/`,
},
});

Expand Down
34 changes: 0 additions & 34 deletions src/scripts/twitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ const getHeaders = async (): Promise<Headers> => {
};
};

const getATHeaders = async (): Promise<Headers> => {
const accessToken = await getAccessToken();

return {
"Client-ID": import.meta.env.TWITCH_CLIENT_ID,
Authorization: `Bearer ${import.meta.env.TWITCH_ACCESS_TOKEN}`,
};
};

export async function getLastStream(): Promise<{
lastStreamUrl: string;
lastThumbnail: string;
Expand Down Expand Up @@ -86,28 +77,3 @@ export async function isOnline(): Promise<string> {
return thumbnail;
}

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}`,
{
headers,
},
);


const body = await response.text();
const { data: subscribers } = JSON.parse(body);

if (subscribers && subscribers.length > 0) {
return {
isSub: true,
err: null
};
}

return {
isSub: false,
err: {status: response.status, message: response.statusText}
};
}

0 comments on commit 478620d

Please sign in to comment.