Streaks: Try to unscrew auth

This commit is contained in:
thororen1234 2026-06-06 23:34:33 -04:00
parent a31c80ba50
commit 21d52f1ea6
No known key found for this signature in database
3 changed files with 8 additions and 14 deletions

View file

@ -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) {

View file

@ -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<string | null> {
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) {

View file

@ -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 {