idk what im doing
This commit is contained in:
parent
c0bf53fdcd
commit
a9dae84539
3 changed files with 23 additions and 2 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
import { identity } from "./stores";
|
||||||
|
import { get } from "svelte/store";
|
||||||
|
|
||||||
export interface Configuration {
|
export interface Configuration {
|
||||||
DISCORD_CLIENT_ID: string;
|
DISCORD_CLIENT_ID: string;
|
||||||
}
|
}
|
||||||
|
@ -8,3 +11,14 @@ export async function fetchConfiguration() {
|
||||||
|
|
||||||
return body;
|
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);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { DiscordSDK } from "@discord/embedded-app-sdk";
|
import { DiscordSDK } from "@discord/embedded-app-sdk";
|
||||||
import type { Configuration } from "./api";
|
import type { Configuration } from "./api";
|
||||||
import { user } from "./stores";
|
import { identity as identityStore, user } from "./stores";
|
||||||
|
|
||||||
export const ACTIVITY_STARTED = Date.now();
|
export const ACTIVITY_STARTED = Date.now();
|
||||||
export let discordSdk: DiscordSDK | null = null;
|
export let discordSdk: DiscordSDK | null = null;
|
||||||
|
@ -24,10 +24,11 @@ export async function authorize(config: Configuration) {
|
||||||
body: JSON.stringify({ code }),
|
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 });
|
const auth = await discordSdk.commands.authenticate({ access_token });
|
||||||
|
|
||||||
user.set(auth.user);
|
user.set(auth.user);
|
||||||
|
identityStore.set(identity);
|
||||||
|
|
||||||
return auth;
|
return auth;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,4 +9,10 @@ interface AuthenticatedUser {
|
||||||
global_name?: string | null | undefined;
|
global_name?: string | null | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Identity {
|
||||||
|
id: string;
|
||||||
|
iv: string;
|
||||||
|
}
|
||||||
|
|
||||||
export const user: Writable<AuthenticatedUser> = writable();
|
export const user: Writable<AuthenticatedUser> = writable();
|
||||||
|
export const identity: Writable<Identity> = writable();
|
||||||
|
|
Loading…
Reference in a new issue