|
| 1 | +# UAuth |
| 2 | + |
| 3 | +Wallet module for connecting Unstoppable Domains to web3-onboard |
| 4 | + |
| 5 | +### Install |
| 6 | + |
| 7 | +<Tabs values={['yarn', 'npm']}> |
| 8 | +<TabPanel value="yarn"> |
| 9 | + |
| 10 | +```sh copy |
| 11 | +yarn add @web3-onboard/uauth |
| 12 | +``` |
| 13 | + |
| 14 | + </TabPanel> |
| 15 | + <TabPanel value="npm"> |
| 16 | + |
| 17 | +```sh copy |
| 18 | +npm install @web3-onboard/uauth |
| 19 | +``` |
| 20 | + |
| 21 | + </TabPanel> |
| 22 | +</Tabs> |
| 23 | + |
| 24 | +## Options |
| 25 | + |
| 26 | +Follow the [Login Client Congifuration Docs](https://docs.unstoppabledomains.com/login-with-unstoppable/login-integration-guides/login-client-configuration/) on the Unstoppable Domains website to get setup with your clientID and redirectUri. |
| 27 | +**Note:** The Redirection URI value(s) in the client configuration MUST exactly match the redirect_uri parameter value used in `UauthInitOptions`. More specifics can be found in the [Rules for Redirect URIs Docs](https://docs.unstoppabledomains.com/login-with-unstoppable/login-integration-guides/login-client-configuration/#rules-for-redirect-uris). |
| 28 | + |
| 29 | +```typescript |
| 30 | +type UauthInitOptions = { |
| 31 | + clientID: string // required and will throw an error if not included: links dapp to Unstoppable Domains for customization |
| 32 | + redirectUri: string // required and will throw an error if not included: used for pop-up and callback redirection |
| 33 | + scope?: string // default = 'openid wallet' |
| 34 | + shouldLoginWithRedirect?: boolean // if true, redirects to your callback page |
| 35 | + bridge?: string // default = 'https://bridge.walletconnect.org' |
| 36 | + qrcodeModalOptions?: { |
| 37 | + mobileLinks: string[] // set the order and list of mobile linking wallets |
| 38 | + } |
| 39 | + connectFirstChainId?: boolean // if true, connects to the first network chain provided |
| 40 | +} |
| 41 | +``` |
| 42 | +
|
| 43 | +## Usage |
| 44 | +
|
| 45 | +```typescript |
| 46 | +import Onboard from '@web3-onboard/core' |
| 47 | +import uauthModule from '@web3-onboard/uauth' |
| 48 | + |
| 49 | +// initialize the module with options |
| 50 | +const uauth = uauthModule({ |
| 51 | + clientID: 'YOUR_CLIENT_ID', |
| 52 | + redirectUri: 'YOUR_REDIRECT_URI', |
| 53 | + scope?: 'YOUR_SCOPES', |
| 54 | + shouldLoginWithRedirect?: false |
| 55 | + bridge?: 'YOUR_CUSTOM_BRIDGE_SERVER', |
| 56 | + qrcodeModalOptions?: { |
| 57 | + mobileLinks: ['rainbow', 'metamask', 'argent', 'trust', 'imtoken', 'pillar'] |
| 58 | + }, |
| 59 | + connectFirstChainId?: true |
| 60 | +}) |
| 61 | + |
| 62 | +// can also initialize with basic options... |
| 63 | +// const uauth = uauthModule({ |
| 64 | +// clientID: "YOUR_CLIENT_ID", |
| 65 | +// redirectUri: "YOUR_REDIRECT_URI" |
| 66 | +// }) |
| 67 | + |
| 68 | +const onboard = Onboard({ |
| 69 | + // ... other Onboard options |
| 70 | + wallets: [ |
| 71 | + uauth |
| 72 | + //... other wallets |
| 73 | + ] |
| 74 | +}) |
| 75 | + |
| 76 | +const connectedWallets = await onboard.connectWallet() |
| 77 | +console.log(connectedWallets) |
| 78 | +``` |
| 79 | + |
| 80 | +### Accessing the UAuth configuration |
| 81 | + |
| 82 | +When Unstoppable Domains is connected the UAuth user instance is exposed. |
| 83 | +This can be used to get information related to the user scopes requested through the `UauthInitOptions`. |
| 84 | + |
| 85 | +```typescript |
| 86 | +const wallets$ = onboard.state.select('wallets').pipe(share()) |
| 87 | +wallets$.subscribe((wallet) => { |
| 88 | + const unstoppableUser = wallet.find((provider) => provider.label === 'Unstoppable') |
| 89 | + if (unstoppableUser) { |
| 90 | + // This will allow insight into the approved user details |
| 91 | + console.log(unstoppableUser.instance.user) |
| 92 | + } |
| 93 | +}) |
| 94 | +``` |
0 commit comments