import { newClientRouter } from "../server-route"; import { sessionRouter } from "./router/session-router"; import { sessionClientStore } from "./store/client-store"; import { ClientSession } from "./type"; export const newClientSession = (arg?: { on: Partial<{ session: ClientSession; messageReceived: () => Promise; afterLogin: () => Promise; afterLogout: () => Promise; afterRecheck: () => Promise; }>; }) => { const store = sessionClientStore(); const client = newClientRouter(sessionRouter); const session: ClientSession = { status: "checking", current: null, async recheck() { const current = await store.load(); if (!current) { this.status = "guest"; } else { this.status = await client.check(current.uid, current.sid); } return { status: this.status }; }, async login(arg: { method: "user-pass"; username: string; password: string; }) {}, async logout() {}, }; session.recheck().then((e) => { console.log(e); }); return session; };