mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
Merge branch 'main' into dev
This commit is contained in:
commit
2d6b8105d2
33 files changed
+916
-390
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/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;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
export function patreonLoginUrl() {
|
||||
const params = new URLSearchParams({
|
||||
response_type: 'code',
|
||||
client_id: process.env.NEXT_PUBLIC_PATREON_CLIENT_ID as string,
|
||||
redirect_uri: process.env.NEXT_PUBLIC_PATREON_REDIRECT_URI as string,
|
||||
scope: 'identity',
|
||||
});
|
||||
|
||||
return `https://www.patreon.com/oauth2/authorize?${params}`;
|
||||
}
|
||||
Reference in new issue
Block a user