Add base auth & ucan request flow (web only)

This commit is contained in:
Paul Frazee 2022-06-14 14:29:47 -05:00
parent 09b78a4634
commit cef133031e
14 changed files with 1555 additions and 290 deletions

View file

@ -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
}