40 lines
1.1 KiB
HTML
40 lines
1.1 KiB
HTML
|
<!doctype html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8" />
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||
|
<title>Auth flow example</title>
|
||
|
</head>
|
||
|
<body>
|
||
|
<button
|
||
|
onclick="window.location.href = globalThis.sdk.GRANT_URL"
|
||
|
id="login_button"
|
||
|
>
|
||
|
Login
|
||
|
</button>
|
||
|
|
||
|
<p id="greeting"></p>
|
||
|
|
||
|
<script type="module">
|
||
|
const app_id = BigInt(prompt("App ID:"));
|
||
|
globalThis.sdk = (await import("/js/app_sdk.js")).from_localstorage(
|
||
|
{
|
||
|
host: window.location.origin,
|
||
|
app_id,
|
||
|
},
|
||
|
);
|
||
|
|
||
|
if (sdk.user_id) {
|
||
|
const user = await sdk.request({
|
||
|
route: "auth/user/me",
|
||
|
method: "GET",
|
||
|
});
|
||
|
|
||
|
document.getElementById("login_button").remove();
|
||
|
document.getElementById("greeting").innerText =
|
||
|
`Hello, ${user.username}!`;
|
||
|
}
|
||
|
</script>
|
||
|
</body>
|
||
|
</html>
|