Fix web build

This commit is contained in:
Paul Frazee 2022-06-15 22:33:16 -05:00
parent 172ed1e2cd
commit de87ec17d1
9 changed files with 88 additions and 56 deletions

View file

@ -1,16 +1,8 @@
import {Linking} from 'react-native'
import * as auth from '@adxp/auth'
import * as ucan from 'ucans'
import {InAppBrowser} from 'react-native-inappbrowser-reborn'
import {isWeb} from '../platform/detection'
import {
getInitialURL,
extractHashFragment,
clearHash,
makeAppUrl,
} from '../platform/urls'
import {getInitialURL, extractHashFragment, clearHash} from '../platform/urls'
import * as authFlow from '../platform/auth-flow'
import * as storage from './storage'
import * as env from '../env'
const SCOPE = auth.writeCap(
'did:key:z6MkfRiFMLzCxxnw6VMrHK8pPFt4QAHS3jX3XM87y9rta6kP',
@ -48,45 +40,7 @@ export async function initialLoadUcanCheck(authStore: ReactNativeStore) {
}
export async function requestAppUcan(authStore: ReactNativeStore) {
const did = await authStore.getDid()
const returnUrl = makeAppUrl()
const fragment = auth.requestAppUcanHashFragment(did, SCOPE, returnUrl)
const url = `${env.AUTH_LOBBY}#${fragment}`
if (isWeb) {
// @ts-ignore window is defined -prf
window.location.href = url
return false
}
if (await InAppBrowser.isAvailable()) {
// use in-app browser
const res = await InAppBrowser.openAuth(url, returnUrl, {
// iOS Properties
ephemeralWebSession: false,
// Android Properties
showTitle: false,
enableUrlBarHiding: true,
enableDefaultShare: false,
})
if (res.type === 'success' && res.url) {
const fragment = extractHashFragment(res.url)
if (fragment) {
const ucan = await parseUrlForUcan(fragment)
if (ucan) {
await authStore.addUcan(ucan)
return true
}
}
} else {
console.log('Not completed', res)
return false
}
} else {
// use system browser
Linking.openURL(url)
}
return true
return authFlow.requestAppUcan(authStore, SCOPE)
}
export class ReactNativeStore extends auth.AuthStore {

View file

@ -7,7 +7,6 @@ import {
import {Environment} from './env'
import * as storage from './storage'
import * as auth from './auth'
import * as urls from '../platform/urls'
const ROOT_STATE_STORAGE_KEY = 'root'