From 21d52f1ea646d5721e5c85aab10122805e464121 Mon Sep 17 00:00:00 2001 From: thororen1234 <78185467+thororen1234@users.noreply.github.com> Date: Sat, 6 Jun 2026 23:34:33 -0400 Subject: [PATCH] Streaks: Try to unscrew auth --- src/equicordplugins/streaks/index.tsx | 4 ++-- .../streaks/stores/AuthorizationStore.tsx | 16 +++++----------- .../streaks/stores/StreaksStore.ts | 2 +- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/equicordplugins/streaks/index.tsx b/src/equicordplugins/streaks/index.tsx index 4e4fe5d63..be95fc176 100644 --- a/src/equicordplugins/streaks/index.tsx +++ b/src/equicordplugins/streaks/index.tsx @@ -94,8 +94,8 @@ export default definePlugin({ const today = moment().format("YYYY-MM-DD"); const cached = useStreaksStore.getState().streaks[recipientId]; - const myFlag = cached && cached.today_date === today && (cached.user_a_id === me ? cached.user_a_today : cached.user_b_today); - const theirFlag = cached && cached.today_date === today && (cached.user_a_id === me ? cached.user_b_today : cached.user_a_today); + const myFlag = cached && cached.today_date != null && cached.today_date === today && (cached.user_a_id === me ? cached.user_a_today : cached.user_b_today); + const theirFlag = cached && cached.today_date != null && cached.today_date === today && (cached.user_a_id === me ? cached.user_b_today : cached.user_a_today); if (message.author.id === me) { if (!myFlag) { diff --git a/src/equicordplugins/streaks/stores/AuthorizationStore.tsx b/src/equicordplugins/streaks/stores/AuthorizationStore.tsx index 970f3b064..447a621e4 100644 --- a/src/equicordplugins/streaks/stores/AuthorizationStore.tsx +++ b/src/equicordplugins/streaks/stores/AuthorizationStore.tsx @@ -3,11 +3,10 @@ * Copyright (c) 2026 Vendicated and contributors * SPDX-License-Identifier: GPL-3.0-or-later */ - import * as DataStore from "@api/DataStore"; import { proxyLazy } from "@utils/lazy"; import { Logger } from "@utils/Logger"; -import { OAuth2AuthorizeModal, openModal,showToast, Toasts, UserStore, zustandCreate, zustandPersist } from "@webpack/common"; +import { OAuth2AuthorizeModal, openModal, showToast, Toasts, UserStore, zustandCreate, zustandPersist } from "@webpack/common"; import { AUTHORIZE_URL, CLIENT_ID } from "../constants"; import { useStreaksStore } from "./StreaksStore"; @@ -21,7 +20,6 @@ interface AuthorizationState { remove: (id: string) => void; isAuthorized: () => boolean; } - const indexedDBStorage = { async getItem(name: string): Promise { return DataStore.get(name).then(v => v ?? null); @@ -33,7 +31,6 @@ const indexedDBStorage = { await DataStore.del(name); }, }; - export const useAuthorizationStore = proxyLazy(() => zustandCreate( zustandPersist( (set: any, get: any) => ({ @@ -50,7 +47,6 @@ export const useAuthorizationStore = proxyLazy(() => zustandCreate( const newTokens = { ...tokens }; delete newTokens[id]; set({ tokens: newTokens }); - init(); }, async authorize() { @@ -71,14 +67,12 @@ export const useAuthorizationStore = proxyLazy(() => zustandCreate( const url = new URL(response.location); const code = url.searchParams.get("code"); if (!code) throw new Error("No code in redirect"); - - const req = await fetch(`${AUTHORIZE_URL}?code=${code}`); - + const req = await fetch(`${AUTHORIZE_URL}?code=${encodeURIComponent(code)}`); if (req?.ok) { - const token = await req.text(); - get().setToken(token); + const { access_token: token } = await req.json(); + if (token) get().setToken(token); } else { - throw new Error("Request not OK"); + throw new Error(`Request not OK: ${req.status}`); } resolve(void 0); } catch (e) { diff --git a/src/equicordplugins/streaks/stores/StreaksStore.ts b/src/equicordplugins/streaks/stores/StreaksStore.ts index 119dab752..288333114 100644 --- a/src/equicordplugins/streaks/stores/StreaksStore.ts +++ b/src/equicordplugins/streaks/stores/StreaksStore.ts @@ -19,7 +19,7 @@ export interface RemoteStreak { last_streak_date: string | null; user_a_today: boolean; user_b_today: boolean; - today_date: string; + today_date: string | null; } export interface StreaksState {