import { env } from "$env/dynamic/public"; import root from "$lib/Utility/root"; import localforage from "localforage"; import type { CommandPaletteAction } from "./actions"; export const authActions = ( user: string | undefined, ): CommandPaletteAction[] => { if (user) return [ { name: "Log Out", url: "#", preventDefault: true, tags: ["auth", "sign", "out", "user"], onClick: async () => { await localforage.removeItem("identity"); await localforage.removeItem("commit"); document.cookie = "user=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; window.location.href = root("/api/authentication/log-out"); }, }, ]; const loginUrl = `https://anilist.co/api/v2/oauth/authorize?client_id=${env.PUBLIC_ANILIST_CLIENT_ID}&redirect_uri=${env.PUBLIC_ANILIST_REDIRECT_URI}&response_type=code`; return [ { name: "Log In", url: loginUrl, preventDefault: true, tags: ["auth", "sign", "in", "anilist"], onClick: async () => { await localforage.setItem( "redirect", window.location.origin + window.location.pathname + window.location.search, ); window.location.href = loginUrl; }, }, ]; };