@synqauth/react-native
v0.2.0
Published
Synq for React Native: sign-in through the system browser, with tokens in the device's secure storage.
Readme
@synqauth/react-native
Synq for React Native: sign-in through the system browser, with tokens in the device's secure storage.
Synq is customer identity for businesses: an OpenID Connect issuer for each of your brands, with Solana wallet, social, email and passkey sign-in. The documentation is at docs.synq.build.
This package is at 0.x and hasn't been published yet: its API can change in any release until Synq's first customer depends on it.
Usage
Register a native app with a redirect URI your app owns: an https link it claims (an iOS universal link, an Android App Link), or a scheme of its own, a reverse domain name such as com.example.app:/callback. Then:
import 'react-native-quick-crypto' // a WebCrypto polyfill: Hermes has none
import * as SecureStore from 'expo-secure-store'
import * as WebBrowser from 'expo-web-browser'
import { SynqNativeProvider, createSynqNative, useAuth, useSession } from '@synqauth/react-native'
const issuer = 'https://acme.auth.synq.build'
const synq = createSynqNative({
issuer,
clientId: 'app_…',
redirectUri: 'https://app.example.com/synq/callback',
webBrowser: WebBrowser,
secureStore: SecureStore,
})
// <SynqNativeProvider synq={synq} issuer={issuer}> around the app, then:
const { isSignedIn } = useSession()
const { signIn, signOut } = useAuth()Sign-in opens the system browser (ASWebAuthenticationSession on iOS, Custom Tabs on Android), never an embedded web view. The session, refresh token included, stays in the device's secure storage.
To sign people in on the app's own screens instead (own-UI sign-in, on for the app in the dashboard), use useSignIn(): password.signIn({ email, password }), emailCode.send(email) and emailCode.verify(code), and the rest. Passkeys, and anything else only the hosted page can do, go on in the system browser with continueInBrowser().
License
MIT
