mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
feat: patreon login
This commit is contained in:
1 parent
03aa690247
commit
a7e89c2147
14 files changed
+260
-191
No files matched your search
@@ -1,10 +0,0 @@
|
||||
import { Region } from '../../constants/regions';
|
||||
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
||||
|
||||
export function authURL(region: Region, callback?: string) {
|
||||
if (typeof window === 'undefined') throw new Error('window is undefined');
|
||||
|
||||
return `https://api.worldoftanks.${region}/wot/auth/login/?application_id=${WARGAMING_APPLICATION_ID}&redirect_uri=${encodeURIComponent(
|
||||
`${window.location.origin}/callback/wargaming/${callback ? `?return=${location.href}` : ''}`,
|
||||
)}`;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { PatreonAuthResponse } from '../../app/auth/[provider]/page';
|
||||
import { mutateApp, useApp } from '../../stores/app';
|
||||
|
||||
export async function extendAuthPatreon() {
|
||||
const { patreon } = useApp.getState().logins;
|
||||
|
||||
if (!patreon) return;
|
||||
|
||||
const data = (await fetch(
|
||||
`/api/auth/patreon/refresh/${patreon.refreshToken}`,
|
||||
).then((response) => response.json())) as PatreonAuthResponse;
|
||||
|
||||
mutateApp((draft) => {
|
||||
draft.logins.patreon = {
|
||||
token: data.access_token,
|
||||
refreshToken: data.refresh_token,
|
||||
expires: Date.now() + data.expires_in * 1000,
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -10,10 +10,10 @@ interface Extension {
|
||||
};
|
||||
}
|
||||
|
||||
export async function extendAuth() {
|
||||
const { login } = useApp.getState();
|
||||
export async function extendAuthWargaming() {
|
||||
const { wargaming } = useApp.getState().logins;
|
||||
|
||||
if (!login) return;
|
||||
if (!wargaming) return;
|
||||
|
||||
// error handling? what's that?
|
||||
/*
|
||||
@@ -42,18 +42,18 @@ export async function extendAuth() {
|
||||
|
||||
const response = await fetch(
|
||||
`https://api.worldoftanks.${idToRegion(
|
||||
login.id,
|
||||
wargaming.id,
|
||||
)}/wot/auth/prolongate/?application_id=${WARGAMING_APPLICATION_ID}&access_token=${
|
||||
login.token
|
||||
wargaming.token
|
||||
}`,
|
||||
);
|
||||
const json = (await response.json()) as Extension;
|
||||
|
||||
mutateApp((draft) => {
|
||||
draft.login = {
|
||||
id: login.id,
|
||||
draft.logins.wargaming = {
|
||||
id: wargaming.id,
|
||||
token: json.data.access_token,
|
||||
expiresAt: json.data.expires_at,
|
||||
expires: json.data.expires_at * 1000,
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { mutateApp } from '../../stores/app';
|
||||
|
||||
export function logout() {
|
||||
export function logoutPatreon() {
|
||||
mutateApp((draft) => {
|
||||
draft.login = undefined;
|
||||
draft.logins.patreon = undefined;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { mutateApp } from '../../stores/app';
|
||||
|
||||
export function logoutWargaming() {
|
||||
mutateApp((draft) => {
|
||||
draft.logins.wargaming = undefined;
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user