grain.social is a photo sharing platform built on atproto.
grain.social
atproto
photography
appview
1import { writable, derived } from "svelte/store";
2import { page } from "$app/stores";
3
4export interface ViewerProfile {
5 did: string;
6 handle: string | null;
7 displayName: string;
8 avatar: string | null;
9}
10
11export const viewer = writable<ViewerProfile | null>(null);
12export const isAuthenticated = derived(page, ($page) => !!$page.data?.viewer);
13export const loginModalOpen = writable(false);
14
15/** Check auth and open login modal if not authenticated. Returns true if authenticated. */
16export function requireAuth(): boolean {
17 let authed = false;
18 isAuthenticated.subscribe((v) => (authed = v))();
19 if (!authed) {
20 loginModalOpen.set(true);
21 return false;
22 }
23 return true;
24}