Link bookmarking tool built on aproto (early alpha)
at main 1.0 kB view raw
1import { action, redirect } from "@solidjs/router" 2import { isValidHandle } from "@atproto/syntax" 3import { err, isErr, tryCatch } from "@/utils/trycatch.ts" 4import { oauthClient } from "./client.ts" 5import { getAuthSession } from "./utils.ts" 6 7export const login = action(async (formData: FormData) => { 8 "use server" 9 10 // Validate 11 const handle = formData.get("handle") 12 13 if (typeof handle !== "string" || !isValidHandle(handle)) { 14 throw err("Invalid handle") 15 } 16 17 const url = await tryCatch(oauthClient.authorize(handle, { 18 scope: "atproto transition:generic", 19 })) 20 21 if (isErr(url)) { 22 console.error(url.error) 23 throw err(url.error) 24 } 25 26 return redirect(url.value.toString()) 27}) 28 29export const isAuthed = async () => { 30 "use server" 31 32 //deno-lint-ignore react-rules-of-hooks 33 const session = await useAuthSession() 34 35 return !!session.did 36} 37 38export const useAuthSession = async () => { 39 "use server" 40 return (await getAuthSession()).data 41}