forked from dfinity/internet-identity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPickAuthenticationMethod.svelte
More file actions
120 lines (113 loc) · 4.01 KB
/
PickAuthenticationMethod.svelte
File metadata and controls
120 lines (113 loc) · 4.01 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<script lang="ts">
import Button from "$lib/components/ui/Button.svelte";
import PasskeyIcon from "$lib/components/icons/PasskeyIcon.svelte";
import SsoIcon from "$lib/components/icons/SsoIcon.svelte";
import Alert from "$lib/components/ui/Alert.svelte";
import ProgressRing from "$lib/components/ui/ProgressRing.svelte";
import { backendCanisterConfig } from "$lib/globals";
import { waitFor } from "$lib/utils/utils";
import Tooltip from "$lib/components/ui/Tooltip.svelte";
import type { OpenIdConfig } from "$lib/generated/internet_identity_types";
import { t } from "$lib/stores/locale.store";
interface Props {
setupOrUseExistingPasskey: () => void;
continueWithOpenId: (config: OpenIdConfig) => Promise<void | "cancelled">;
signInWithSso: () => void;
}
const {
setupOrUseExistingPasskey,
continueWithOpenId,
signInWithSso,
}: Props = $props();
let authenticatingProviderId = $state<string>();
let cancelledProviderId = $state<string>();
const handleContinueWithOpenId = async (config: OpenIdConfig) => {
authenticatingProviderId = config.client_id;
const result = await continueWithOpenId(config);
authenticatingProviderId = undefined;
if (result === "cancelled") {
cancelledProviderId = config.client_id;
await waitFor(4000);
cancelledProviderId = undefined;
}
};
const supportsPasskeys = window.PublicKeyCredential !== undefined;
const openIdProviders = backendCanisterConfig.openid_configs?.[0] ?? [];
</script>
<div class="flex flex-col items-stretch gap-5">
{#if !supportsPasskeys}
<Alert
title={$t`Passkeys not available here`}
description={$t`Passkeys are unavailable on this device or browser. Please choose another sign-in method to continue.`}
/>
{/if}
<div class="flex flex-col items-stretch gap-3">
<Button
onclick={setupOrUseExistingPasskey}
disabled={!supportsPasskeys || authenticatingProviderId !== undefined}
size="xl"
variant={"secondary"}
>
<PasskeyIcon />
{$t`Continue with passkey`}
</Button>
<div class="flex flex-row flex-nowrap justify-stretch gap-3">
{#each openIdProviders as provider}
{@const name = provider.name}
<Tooltip
label={$t`Interaction canceled. Please try again.`}
hidden={cancelledProviderId !== provider.client_id}
manual
>
<Button
onclick={() => handleContinueWithOpenId(provider)}
variant="secondary"
disabled={authenticatingProviderId !== undefined}
size="xl"
class="flex-1"
aria-label={$t`Continue with ${name}`}
>
{#if authenticatingProviderId === provider.client_id}
<ProgressRing />
{:else}
<div class="size-6">
{@html provider.logo}
</div>
{/if}
</Button>
</Tooltip>
{/each}
<!--
SSO entry is always rendered. Registration is enforced on the
backend (via the `ALLOWED_DISCOVERY_DOMAINS` canary allowlist on
`add_discoverable_oidc_config`), so unregistered domains surface as
an error inside the SignInWithSso screen rather than being gated
here — we keep this option visible so users know the mechanism
exists.
-->
<Button
onclick={signInWithSso}
variant="secondary"
disabled={authenticatingProviderId !== undefined}
size="xl"
class="flex-1"
aria-label={$t`Continue with SSO`}
>
<SsoIcon class="size-6" />
</Button>
</div>
</div>
<div class="border-border-tertiary border-t"></div>
<div class="flex flex-row items-center justify-between gap-4">
<p class="text-text-secondary text-sm">
{$t`Lost access to your identity?`}
</p>
<a
href="/recovery"
target="_blank"
class="text-text-primary text-sm font-semibold outline-0 hover:underline focus-visible:underline"
>
{$t`Recover`}
</a>
</div>
</div>