-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathjsmodule.html
More file actions
51 lines (43 loc) · 1.72 KB
/
jsmodule.html
File metadata and controls
51 lines (43 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Xumm Web3 demo</title>
</head>
<body>
<h1>Sample</h1>
<h2 id="sub">... (please sign in)</h2>
<button id="auth">Auth</button>
<button id="logout">Logout</button>
<br /><br />
<a href="https://github.com/XRPL-Labs/XummPkce/blob/main/sample/jsmodule.html" target="_blank">Source on Github</a>
<br /><br />
<script type="module">
import 'https://xumm.app/assets/cdn/xumm-oauth2-pkce.min.js?v=2.7.1'
const xumm = new XummPkce('47d328db-0b34-4451-a258-393480c9b4cd', {
implicit: true, // Implicit: allows to e.g. move from social browser to stock browser
redirectUrl: document.location.href + '?custom_state=test'
})
document.getElementById('auth').onclick = () => {
xumm.authorize().catch(e => console.log('e', e))
}
document.getElementById('logout').onclick = () => {
xumm.logout()
document.getElementById('sub').innerText = '... (please sign in)'
}
xumm.on("error", (error) => {
console.log("error", error)
})
xumm.on("success", async () => {
const state = await xumm.state() // state.sdk = instance of https://www.npmjs.com/package/xumm-sdk
document.getElementById('sub').innerText = state?.me?.sub
})
xumm.on("retrieved", async () => {
console.log("Retrieved: from localStorage or mobile browser redirect")
const state = await xumm.state() // state.sdk = instance of https://www.npmjs.com/package/xumm-sdk
document.getElementById('sub').innerText = state?.me?.sub
})
</script>
</body>
</html>