summaryrefslogtreecommitdiff
path: root/webapp/public/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'webapp/public/index.html')
-rw-r--r--webapp/public/index.html62
1 files changed, 62 insertions, 0 deletions
diff --git a/webapp/public/index.html b/webapp/public/index.html
new file mode 100644
index 0000000..fabc8a0
--- /dev/null
+++ b/webapp/public/index.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <title></title>
+ <script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
+</head>
+
+<body>
+ <button onclick="connect()">Login with Web3</button>
+
+ <script type="text/javascript">
+ let account = null;
+ let accessToken = null;
+ const connect = async () => {
+ if (window.ethereum) {
+ await window.ethereum.send('eth_requestAccounts')
+ window.w3 = new Web3(window.ethereum)
+ var accounts = await w3.eth.getAccounts()
+ account = accounts[0];
+
+ accessToken = await authenticate()
+
+ let opts = {
+ method: 'GET',
+ headers: {
+ 'Content-Type': "application/json",
+ 'Authorization': `Bearer ${accessToken}`
+ }
+ }
+
+ let res = await fetch(`/secret`, opts)
+ alert(await res.text())
+ }
+ }
+
+ const authenticate = async () => {
+ let res = await fetch(`/nonce?address=${account}`)
+ let resBody = await res.json()
+
+ let signature = await w3.eth.personal.sign(resBody.message, account)
+
+ let opts = {
+ method: 'POST',
+ headers: {
+ 'Content-Type': "application/json",
+ 'Authorization': `Bearer ${resBody.tempToken}`
+ }
+ }
+
+ res = await fetch(`/verify?signature=${signature}`, opts)
+ resBody = await res.json()
+
+ console.log(resBody)
+ return resBody.token
+ }
+ </script>
+</body>
+
+</html> \ No newline at end of file