about summary refs log tree commit diff
path: root/src/state/index.ts
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2022-06-14 14:29:47 -0500
committerPaul Frazee <pfrazee@gmail.com>2022-06-14 14:29:47 -0500
commitcef133031e501f8f73c66a379de38b1041287743 (patch)
treeb628150cbee4facbcbfc06599baaf4c108949995 /src/state/index.ts
parent09b78a46343088a2790dab067bd4fd8384957311 (diff)
downloadvoidsky-cef133031e501f8f73c66a379de38b1041287743.tar.zst
Add base auth & ucan request flow (web only)
Diffstat (limited to 'src/state/index.ts')
-rw-r--r--src/state/index.ts12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/state/index.ts b/src/state/index.ts
index 496f3631d..0e70055e0 100644
--- a/src/state/index.ts
+++ b/src/state/index.ts
@@ -6,6 +6,7 @@ import {
 } from './models/root-store'
 import {Environment} from './env'
 import * as storage from './storage'
+import * as auth from '../api/auth'
 
 const ROOT_STATE_STORAGE_KEY = 'root'
 
@@ -14,6 +15,7 @@ export async function setupState() {
   let data: any
 
   const env = new Environment()
+  await env.setup()
   try {
     data = (await storage.load(ROOT_STATE_STORAGE_KEY)) || {}
     rootStore = RootStoreModel.create(data, env)
@@ -27,6 +29,16 @@ export async function setupState() {
     storage.save(ROOT_STATE_STORAGE_KEY, snapshot),
   )
 
+  if (env.authStore) {
+    const isAuthed = await auth.isAuthed(env.authStore)
+    rootStore.session.setAuthed(isAuthed)
+    const ucan = await auth.parseUrlForUcan()
+    if (ucan) {
+      await env.authStore.addUcan(ucan)
+      rootStore.session.setAuthed(true)
+    }
+  }
+
   return rootStore
 }