28 lines
637 B
TypeScript
28 lines
637 B
TypeScript
import { defineStore } from "pinia";
|
|
import { whoami } from "~/netcode";
|
|
|
|
export const useAuthStore = defineStore("auth", {
|
|
state: () => ({
|
|
selfUser: {} as { userId?: string; image?: string; username?: string },
|
|
logged: false,
|
|
}),
|
|
actions: {
|
|
async whoami() {
|
|
try {
|
|
const data = await whoami().then((data) => {
|
|
this.logged = true;
|
|
return data;
|
|
});
|
|
|
|
Object.assign(this.selfUser, data.value);
|
|
} catch (e) {}
|
|
},
|
|
oauth2_register_discord: () => {
|
|
throw Error("not implemented");
|
|
},
|
|
},
|
|
persist: {
|
|
storage: persistedState.localStorage,
|
|
},
|
|
});
|