-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallback.astro
More file actions
44 lines (39 loc) · 1.45 KB
/
Copy pathcallback.astro
File metadata and controls
44 lines (39 loc) · 1.45 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
---
import Layout from '../components/Layout.astro';
---
<Layout title="Signing in…">
<h1>Signing in…</h1>
<p id="status" class="muted">Completing sign-in with Cognito.</p>
<p id="error" class="error" hidden></p>
<a id="retry" class="button" href="/" hidden>Back to sign in</a>
</Layout>
<script>
import { completeSignIn, CallbackError, TokenExchangeError } from '../lib/auth';
import { loadAuthConfig, ConfigError } from '../lib/config';
import { storeSession } from '../lib/session';
const statusEl = document.getElementById('status') as HTMLParagraphElement;
const errorEl = document.getElementById('error') as HTMLParagraphElement;
const retryEl = document.getElementById('retry') as HTMLAnchorElement;
function fail(message: string): void {
statusEl.hidden = true;
errorEl.textContent = message;
errorEl.hidden = false;
retryEl.hidden = false;
}
(async () => {
try {
const config = loadAuthConfig();
const tokens = await completeSignIn(config, window.location.href);
storeSession(tokens);
window.location.assign('/dashboard');
} catch (error) {
if (error instanceof ConfigError) {
fail(`This deployment isn't configured yet: ${error.message}`);
} else if (error instanceof CallbackError || error instanceof TokenExchangeError) {
fail(error.message);
} else {
fail(error instanceof Error ? error.message : 'Sign-in failed.');
}
}
})();
</script>