mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
fix: patreon login
This commit is contained in:
1 parent
a17a8888ff
commit
9bc745bc0e
3 files changed
+38
-4
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import { assertSecret, type BlitzkitResponse } from '@blitzkit/core';
|
||||
import type { APIContext } from 'astro';
|
||||
|
||||
export const prerender = false;
|
||||
|
||||
export async function GET({ request, params }: APIContext) {
|
||||
const code = request.headers.get('code');
|
||||
|
||||
if (!code) {
|
||||
return Response.json({
|
||||
status: 'error',
|
||||
error: 'UNDEFINED_CODE',
|
||||
} satisfies BlitzkitResponse);
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
`https://www.patreon.com/api/oauth2/token?code=${
|
||||
code
|
||||
}&grant_type=authorization_code&client_id=${assertSecret(
|
||||
import.meta.env.PUBLIC_PATREON_CLIENT_ID,
|
||||
)}&client_secret=${assertSecret(
|
||||
import.meta.env.PATREON_CLIENT_SECRET,
|
||||
)}&redirect_uri=${assertSecret(
|
||||
import.meta.env.PUBLIC_PATREON_REDIRECT_URI,
|
||||
)}`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
},
|
||||
);
|
||||
const json = await response.json();
|
||||
|
||||
return Response.json(json);
|
||||
}
|
||||
@@ -3,5 +3,5 @@ import type { APIContext } from 'astro';
|
||||
export const prerender = false;
|
||||
|
||||
export async function GET({}: APIContext) {
|
||||
return Response.json({ hello: 'world' });
|
||||
return Response.json({ hello: Math.random() });
|
||||
}
|
||||
@@ -62,9 +62,9 @@ function Content({ provider }: AuthorizeProps) {
|
||||
case 'patreon': {
|
||||
if (!searchParams.get('code')) break;
|
||||
|
||||
const response = await fetch(
|
||||
`/api/patreon/auth/${searchParams.get('code')}`,
|
||||
);
|
||||
const response = await fetch('/api/patreon/auth', {
|
||||
headers: { code: searchParams.get('code')! },
|
||||
});
|
||||
const data = (await response.json()) as PatreonAuthResponse;
|
||||
|
||||
mutateApp((draft) => {
|
||||
|
||||
Reference in new issue
Block a user