|
1 | 1 | <!doctype html> |
2 | 2 | <html lang="en"> |
3 | | - <head> |
4 | | - <meta charset="utf-8" /> |
5 | | - <title>Signing you in…</title> |
6 | | - <link rel="stylesheet" href="/css/bootstrap.min.css" /> |
7 | | - <link rel="stylesheet" href="/css/main.css" /> |
8 | | - </head> |
9 | | - <body> |
10 | | - <div id="error-message" class="alert alert-danger" style="display: none" role="alert"> |
11 | | - <div class="message"></div> |
12 | | - <pre class="details"></pre> |
13 | | - </div> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <title>Signing you in…</title> |
| 6 | + <link rel="stylesheet" href="/css/bootstrap.min.css"/> |
| 7 | + <link rel="stylesheet" href="/css/main.css"/> |
| 8 | +</head> |
| 9 | +<body> |
| 10 | +<div id="error-message" class="alert alert-danger" style="display: none;" role="alert"> |
| 11 | + <div class="message"></div> |
| 12 | + <pre class="details"></pre> |
| 13 | +</div> |
14 | 14 |
|
15 | | - <script type="module" th:inline="javascript"> |
16 | | - import { showErrorMessage, checkHttpError } from "/js/errors.js"; |
17 | | - import { parsePayload } from "/js/payload.js"; |
| 15 | +<script type="module" th:inline="javascript"> |
| 16 | + import {showErrorMessage, checkHttpError} from "/js/errors.js"; |
18 | 17 |
|
19 | | - // Using an async IIFE for mobile WebView compatibility: |
20 | | - // top-level await is not supported in some mobile browsers/WebViews. |
21 | | - (async function () { |
22 | | - const payload = parsePayload("Authentication"); |
23 | | - const authToken = payload["auth_token"]; |
24 | | - const response = await fetch(/*[[${loginProcessingPath}]]*/, { |
25 | | - method: "POST", |
26 | | - headers: { |
27 | | - "Content-Type": "application/json", |
28 | | - "X-CSRF-TOKEN": /*[[${csrfToken}]]*/ |
29 | | - }, |
30 | | - body: JSON.stringify(authToken), |
31 | | - credentials: "include" |
32 | | - }); |
33 | | - await checkHttpError(response); |
| 18 | + // Using an async IIFE for mobile WebView compatibility: |
| 19 | + // top-level await is not supported in some mobile browsers/WebViews. |
| 20 | + (async function () { |
| 21 | + const fragment = window.location.hash.slice(1); |
| 22 | + if (!fragment) { |
| 23 | + throw new Error("Missing authentication payload"); |
| 24 | + } |
34 | 25 |
|
35 | | - window.location.replace("/welcome"); |
36 | | - })().catch((error) => { |
37 | | - console.error(error); |
38 | | - showErrorMessage(error); |
39 | | - }); |
40 | | - </script> |
41 | | - </body> |
| 26 | + let payload; |
| 27 | + try { |
| 28 | + payload = JSON.parse(atob(fragment)); |
| 29 | + } catch (e) { |
| 30 | + console.error(e) |
| 31 | + throw new Error("Failed to parse the authentication response"); |
| 32 | + } |
| 33 | + |
| 34 | + if (payload.error) { |
| 35 | + const error = new Error(payload.message ?? "Authentication failed"); |
| 36 | + error.code = payload.code; |
| 37 | + throw error; |
| 38 | + } |
| 39 | + |
| 40 | + const authToken = payload["auth_token"]; |
| 41 | + const response = await fetch(/*[[${loginProcessingPath}]]*/, { |
| 42 | + method: "POST", |
| 43 | + headers: { |
| 44 | + "Content-Type": "application/json", |
| 45 | + "X-CSRF-TOKEN": /*[[${csrfToken}]]*/ |
| 46 | + }, |
| 47 | + body: JSON.stringify(authToken), |
| 48 | + credentials: "include" |
| 49 | + }); |
| 50 | + await checkHttpError(response); |
| 51 | + |
| 52 | + window.location.replace("/welcome"); |
| 53 | + })().catch((error) => { |
| 54 | + console.error(error); |
| 55 | + showErrorMessage(error); |
| 56 | + }); |
| 57 | +</script> |
| 58 | +</body> |
42 | 59 | </html> |
0 commit comments