idk what im doing

This commit is contained in:
cirroskais 2024-03-18 23:02:48 -04:00
parent c0bf53fdcd
commit a9dae84539
No known key found for this signature in database
GPG key ID: 5FC73EBF2678E33D
3 changed files with 23 additions and 2 deletions

View file

@ -1,3 +1,6 @@
import { identity } from "./stores";
import { get } from "svelte/store";
export interface Configuration {
DISCORD_CLIENT_ID: string;
}
@ -8,3 +11,14 @@ export async function fetchConfiguration() {
return body;
}
export async function connect() {
const searchParams = new URLSearchParams();
searchParams.set("id", get(identity).id);
searchParams.set("iv", get(identity).iv);
const socket = new WebSocket("/api/ws?" + searchParams.toString());
socket.onmessage = (event) => {
console.log(event);
};
}

View file

@ -1,6 +1,6 @@
import { DiscordSDK } from "@discord/embedded-app-sdk";
import type { Configuration } from "./api";
import { user } from "./stores";
import { identity as identityStore, user } from "./stores";
export const ACTIVITY_STARTED = Date.now();
export let discordSdk: DiscordSDK | null = null;
@ -24,10 +24,11 @@ export async function authorize(config: Configuration) {
body: JSON.stringify({ code }),
});
const { access_token } = await response.json();
const { access_token, identity } = await response.json();
const auth = await discordSdk.commands.authenticate({ access_token });
user.set(auth.user);
identityStore.set(identity);
return auth;
}

View file

@ -9,4 +9,10 @@ interface AuthenticatedUser {
global_name?: string | null | undefined;
}
interface Identity {
id: string;
iv: string;
}
export const user: Writable<AuthenticatedUser> = writable();
export const identity: Writable<Identity> = writable();