Fix floating promise lint errors and apply code formatting
- Add void operator to async calls in $effect() blocks to satisfy noFloatingPromises lint rule: - passkey/+page.svelte: void authenticate() - verify/+page.svelte: void verifyEmail() - Apply biome formatter import reorganization across auth files Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { Alert, AlertDescription } from "$lib/components/ui/alert";
|
||||
import { AlertCircle } from "@lucide/svelte";
|
||||
import { AlertCircle } from "@lucide/svelte";
|
||||
import { Alert, AlertDescription } from "$lib/components/ui/alert";
|
||||
|
||||
interface Props {
|
||||
interface Props {
|
||||
message: string;
|
||||
}
|
||||
}
|
||||
|
||||
let { message }: Props = $props();
|
||||
let { message }: Props = $props();
|
||||
</script>
|
||||
|
||||
{#if message}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export { default as ErrorAlert } from "./error-alert.svelte";
|
||||
export { default as PasswordFormField } from "./password-form-field.svelte";
|
||||
export { default as PasswordInput } from "./password-input.svelte";
|
||||
export { default as PasswordStrength } from "./password-strength.svelte";
|
||||
export { default as PasswordFormField } from "./password-form-field.svelte";
|
||||
export { default as ErrorAlert } from "./error-alert.svelte";
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<script lang="ts">
|
||||
import { Label } from "$lib/components/ui/label";
|
||||
import PasswordInput from "./password-input.svelte";
|
||||
import PasswordStrength from "./password-strength.svelte";
|
||||
import type { HTMLInputAttributes } from "svelte/elements";
|
||||
import type { HTMLInputAttributes } from "svelte/elements";
|
||||
import { Label } from "$lib/components/ui/label";
|
||||
import PasswordInput from "./password-input.svelte";
|
||||
import PasswordStrength from "./password-strength.svelte";
|
||||
|
||||
interface Props {
|
||||
interface Props {
|
||||
id?: string;
|
||||
label?: string;
|
||||
value?: string;
|
||||
@@ -14,9 +14,9 @@
|
||||
autocomplete?: HTMLInputAttributes["autocomplete"];
|
||||
required?: boolean;
|
||||
disabled?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
let {
|
||||
let {
|
||||
id = "password",
|
||||
label = "Password",
|
||||
value = $bindable(""),
|
||||
@@ -26,7 +26,7 @@
|
||||
autocomplete = "current-password",
|
||||
required = false,
|
||||
disabled = false,
|
||||
}: Props = $props();
|
||||
}: Props = $props();
|
||||
</script>
|
||||
|
||||
<div class="space-y-2">
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<script lang="ts">
|
||||
import type { HTMLInputAttributes } from "svelte/elements";
|
||||
import { Input } from "$lib/components/ui/input";
|
||||
import { Button } from "$lib/components/ui/button";
|
||||
import { Eye, EyeOff } from "@lucide/svelte";
|
||||
import { cn } from "$lib/utils";
|
||||
import type { HTMLInputAttributes } from "svelte/elements";
|
||||
import { Eye, EyeOff } from "@lucide/svelte";
|
||||
import { Button } from "$lib/components/ui/button";
|
||||
import { Input } from "$lib/components/ui/input";
|
||||
import { cn } from "$lib/utils";
|
||||
|
||||
interface Props {
|
||||
interface Props {
|
||||
value?: string;
|
||||
placeholder?: string;
|
||||
id?: string;
|
||||
@@ -14,9 +14,9 @@
|
||||
disabled?: boolean;
|
||||
autocomplete?: HTMLInputAttributes["autocomplete"];
|
||||
class?: string;
|
||||
}
|
||||
}
|
||||
|
||||
let {
|
||||
let {
|
||||
value = $bindable(""),
|
||||
placeholder = "Enter your password",
|
||||
id = "password",
|
||||
@@ -25,13 +25,13 @@
|
||||
disabled = false,
|
||||
autocomplete = "current-password",
|
||||
class: className = "",
|
||||
}: Props = $props();
|
||||
}: Props = $props();
|
||||
|
||||
let showPassword = $state(false);
|
||||
let showPassword = $state(false);
|
||||
|
||||
function toggleVisibility() {
|
||||
function toggleVisibility() {
|
||||
showPassword = !showPassword;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="relative">
|
||||
|
||||
@@ -1,27 +1,31 @@
|
||||
<script lang="ts">
|
||||
import zxcvbn from "zxcvbn";
|
||||
import zxcvbn from "zxcvbn";
|
||||
|
||||
interface Props {
|
||||
interface Props {
|
||||
password: string;
|
||||
userInputs?: string[];
|
||||
}
|
||||
}
|
||||
|
||||
let { password, userInputs = [] }: Props = $props();
|
||||
let { password, userInputs = [] }: Props = $props();
|
||||
|
||||
// Compute password strength using zxcvbn
|
||||
const result = $derived(password ? zxcvbn(password, userInputs) : null);
|
||||
const score = $derived(result?.score ?? 0);
|
||||
// Compute password strength using zxcvbn
|
||||
const result = $derived(password ? zxcvbn(password, userInputs) : null);
|
||||
const score = $derived(result?.score ?? 0);
|
||||
|
||||
// Strength labels and colors
|
||||
const strengthConfig = [
|
||||
{ label: "Very weak", color: "bg-destructive", textColor: "text-destructive" },
|
||||
// Strength labels and colors
|
||||
const strengthConfig = [
|
||||
{
|
||||
label: "Very weak",
|
||||
color: "bg-destructive",
|
||||
textColor: "text-destructive",
|
||||
},
|
||||
{ label: "Weak", color: "bg-destructive", textColor: "text-destructive" },
|
||||
{ label: "Fair", color: "bg-warning", textColor: "text-warning" },
|
||||
{ label: "Good", color: "bg-success", textColor: "text-success" },
|
||||
{ label: "Strong", color: "bg-success", textColor: "text-success" },
|
||||
] as const;
|
||||
] as const;
|
||||
|
||||
const config = $derived(strengthConfig[score]);
|
||||
const config = $derived(strengthConfig[score]);
|
||||
</script>
|
||||
|
||||
{#if password}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<script lang="ts">
|
||||
import type { HTMLAttributes } from "svelte/elements";
|
||||
import { cn, type WithElementRef } from "$lib/utils.js";
|
||||
import type { HTMLAttributes } from "svelte/elements";
|
||||
import { cn, type WithElementRef } from "$lib/utils.js";
|
||||
|
||||
let {
|
||||
let {
|
||||
ref = $bindable(null),
|
||||
class: className,
|
||||
children,
|
||||
...restProps
|
||||
}: WithElementRef<HTMLAttributes<HTMLDivElement>> = $props();
|
||||
}: WithElementRef<HTMLAttributes<HTMLDivElement>> = $props();
|
||||
</script>
|
||||
|
||||
<div
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<script lang="ts">
|
||||
import type { HTMLAttributes } from "svelte/elements";
|
||||
import { cn, type WithElementRef } from "$lib/utils.js";
|
||||
import type { HTMLAttributes } from "svelte/elements";
|
||||
import { cn, type WithElementRef } from "$lib/utils.js";
|
||||
|
||||
let {
|
||||
let {
|
||||
ref = $bindable(null),
|
||||
class: className,
|
||||
children,
|
||||
...restProps
|
||||
}: WithElementRef<HTMLAttributes<HTMLDivElement>> = $props();
|
||||
}: WithElementRef<HTMLAttributes<HTMLDivElement>> = $props();
|
||||
</script>
|
||||
|
||||
<div
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts" module>
|
||||
import { type VariantProps, tv } from "tailwind-variants";
|
||||
import { tv, type VariantProps } from "tailwind-variants";
|
||||
|
||||
export const alertVariants = tv({
|
||||
export const alertVariants = tv({
|
||||
base: "relative grid w-full grid-cols-[0_1fr] items-start gap-y-0.5 rounded-lg border px-4 py-3 text-sm has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] has-[>svg]:gap-x-3 [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",
|
||||
variants: {
|
||||
variant: {
|
||||
@@ -13,9 +13,9 @@
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
export type AlertVariant = VariantProps<typeof alertVariants>["variant"];
|
||||
export type AlertVariant = VariantProps<typeof alertVariants>["variant"];
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import Root from "./alert.svelte";
|
||||
import Description from "./alert-description.svelte";
|
||||
import Title from "./alert-title.svelte";
|
||||
export { alertVariants, type AlertVariant } from "./alert.svelte";
|
||||
|
||||
export { type AlertVariant, alertVariants } from "./alert.svelte";
|
||||
|
||||
export {
|
||||
Root,
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
import Root from "./loading-button.svelte";
|
||||
|
||||
export {
|
||||
Root,
|
||||
Root as LoadingButton,
|
||||
};
|
||||
export { Root, Root as LoadingButton };
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
<script lang="ts">
|
||||
import { Button, type ButtonProps } from "$lib/components/ui/button";
|
||||
import { Loader2 } from "@lucide/svelte";
|
||||
import type { Snippet } from "svelte";
|
||||
import type { Snippet } from "svelte";
|
||||
import { Loader2 } from "@lucide/svelte";
|
||||
import { Button, type ButtonProps } from "$lib/components/ui/button";
|
||||
|
||||
interface Props extends ButtonProps {
|
||||
interface Props extends ButtonProps {
|
||||
loading?: boolean;
|
||||
loadingText?: string;
|
||||
children: Snippet;
|
||||
}
|
||||
}
|
||||
|
||||
let {
|
||||
let {
|
||||
loading = false,
|
||||
loadingText,
|
||||
children,
|
||||
disabled,
|
||||
...rest
|
||||
}: Props = $props();
|
||||
}: Props = $props();
|
||||
</script>
|
||||
|
||||
<Button disabled={loading || disabled} {...rest}>
|
||||
|
||||
@@ -61,13 +61,16 @@ export function hasActiveLoginFlow(): boolean {
|
||||
* Get masked email for display (e.g., "j***@example.com")
|
||||
*/
|
||||
export function getMaskedEmail(): string {
|
||||
if (!loginFlowState.email) return "";
|
||||
if (!loginFlowState.email) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const [local, domain] = loginFlowState.email.split("@");
|
||||
if (!domain) return loginFlowState.email;
|
||||
if (!domain) {
|
||||
return loginFlowState.email;
|
||||
}
|
||||
|
||||
const maskedLocal =
|
||||
local.length > 1 ? local[0] + "***" : local + "***";
|
||||
const maskedLocal = local.length > 1 ? `${local[0]}***` : `${local}***`;
|
||||
|
||||
return `${maskedLocal}@${domain}`;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { parsePhoneNumberWithError, isValidPhoneNumber } from "libphonenumber-js";
|
||||
import {
|
||||
isValidPhoneNumber,
|
||||
parsePhoneNumberWithError,
|
||||
} from "libphonenumber-js";
|
||||
|
||||
/**
|
||||
* Validates email format using a simple regex pattern.
|
||||
@@ -12,8 +15,13 @@ export function isValidEmail(email: string): boolean {
|
||||
* Validates and formats phone numbers using libphonenumber-js.
|
||||
* Returns validation status and optionally the formatted number.
|
||||
*/
|
||||
export function validatePhone(value: string): { valid: boolean; formatted?: string } {
|
||||
if (!value) return { valid: true };
|
||||
export function validatePhone(value: string): {
|
||||
valid: boolean;
|
||||
formatted?: string;
|
||||
} {
|
||||
if (!value) {
|
||||
return { valid: true };
|
||||
}
|
||||
try {
|
||||
const phone = parsePhoneNumberWithError(value);
|
||||
if (isValidPhoneNumber(phone.number)) {
|
||||
@@ -30,8 +38,11 @@ export function validatePhone(value: string): { valid: boolean; formatted?: stri
|
||||
*/
|
||||
export function maskEmail(email: string): string {
|
||||
const [local, domain] = email.split("@");
|
||||
if (!domain) return email;
|
||||
const masked = local.length > 1
|
||||
if (!domain) {
|
||||
return email;
|
||||
}
|
||||
const masked =
|
||||
local.length > 1
|
||||
? `${local[0]}${"*".repeat(Math.min(local.length - 1, 3))}`
|
||||
: local;
|
||||
return `${masked}@${domain}`;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from "svelte";
|
||||
import type { Snippet } from "svelte";
|
||||
|
||||
interface Props {
|
||||
interface Props {
|
||||
children: Snippet;
|
||||
}
|
||||
}
|
||||
|
||||
let { children }: Props = $props();
|
||||
let { children }: Props = $props();
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
|
||||
@@ -1,58 +1,58 @@
|
||||
<script lang="ts">
|
||||
import { goto } from "$app/navigation";
|
||||
import { createQuery } from "@tanstack/svelte-query";
|
||||
import { api } from "$lib/api/client";
|
||||
import {
|
||||
loginFlowState,
|
||||
import { AlertCircle, Loader2, Mail, RefreshCw } from "@lucide/svelte";
|
||||
import { createQuery } from "@tanstack/svelte-query";
|
||||
import { goto } from "$app/navigation";
|
||||
import { api } from "$lib/api/client";
|
||||
import { ErrorAlert } from "$lib/components/auth";
|
||||
import { Alert, AlertDescription } from "$lib/components/ui/alert";
|
||||
import { Button } from "$lib/components/ui/button";
|
||||
import { LoadingButton } from "$lib/components/ui/loading-button";
|
||||
import {
|
||||
clearLoginFlowState,
|
||||
getMaskedEmail,
|
||||
} from "$lib/stores/auth.svelte";
|
||||
import { ErrorAlert } from "$lib/components/auth";
|
||||
import { Button } from "$lib/components/ui/button";
|
||||
import { LoadingButton } from "$lib/components/ui/loading-button";
|
||||
import { Alert, AlertDescription } from "$lib/components/ui/alert";
|
||||
import { Loader2, Mail, AlertCircle, RefreshCw } from "@lucide/svelte";
|
||||
loginFlowState,
|
||||
} from "$lib/stores/auth.svelte";
|
||||
|
||||
let resendCooldown = $state(0);
|
||||
let isResending = $state(false);
|
||||
let resendError = $state<string | null>(null);
|
||||
let resendCooldown = $state(0);
|
||||
let isResending = $state(false);
|
||||
let resendError = $state<string | null>(null);
|
||||
|
||||
// Guard: redirect to /auth/login if no active login flow
|
||||
$effect(() => {
|
||||
// Guard: redirect to /auth/login if no active login flow
|
||||
$effect(() => {
|
||||
if (!loginFlowState.email) {
|
||||
goto("/auth/login");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Poll for login completion every 3 seconds
|
||||
// In Svelte 5 with TanStack Query v6, options are passed as a thunk (function)
|
||||
const statusQuery = createQuery(() => ({
|
||||
// Poll for login completion every 3 seconds
|
||||
// In Svelte 5 with TanStack Query v6, options are passed as a thunk (function)
|
||||
const statusQuery = createQuery(() => ({
|
||||
queryKey: ["loginStatus"],
|
||||
queryFn: () => api.auth.loginIfRequestIsCompleted(),
|
||||
refetchInterval: 3000,
|
||||
enabled: !!loginFlowState.email,
|
||||
}));
|
||||
}));
|
||||
|
||||
// Watch for completed status
|
||||
// In TanStack Query v6 for Svelte 5, query results are reactive objects (not stores)
|
||||
$effect(() => {
|
||||
// Watch for completed status
|
||||
// In TanStack Query v6 for Svelte 5, query results are reactive objects (not stores)
|
||||
$effect(() => {
|
||||
if (statusQuery.data?.status === "completed") {
|
||||
clearLoginFlowState();
|
||||
goto(statusQuery.data.redirectTo || "/performance");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Handle cooldown timer
|
||||
$effect(() => {
|
||||
// Handle cooldown timer
|
||||
$effect(() => {
|
||||
if (resendCooldown > 0) {
|
||||
const timer = setTimeout(() => {
|
||||
resendCooldown = resendCooldown - 1;
|
||||
resendCooldown -= 1;
|
||||
}, 1000);
|
||||
return () => clearTimeout(timer);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
async function handleResendEmail() {
|
||||
async function handleResendEmail() {
|
||||
resendError = null;
|
||||
isResending = true;
|
||||
|
||||
@@ -64,12 +64,12 @@
|
||||
} finally {
|
||||
isResending = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleDifferentEmail() {
|
||||
function handleDifferentEmail() {
|
||||
clearLoginFlowState();
|
||||
goto("/auth/login");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="space-y-6">
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
<script lang="ts">
|
||||
import { api } from "$lib/api/client";
|
||||
import { ErrorAlert } from "$lib/components/auth";
|
||||
import { Alert, AlertDescription } from "$lib/components/ui/alert";
|
||||
import { Button } from "$lib/components/ui/button";
|
||||
import { Input } from "$lib/components/ui/input";
|
||||
import { Label } from "$lib/components/ui/label";
|
||||
import { LoadingButton } from "$lib/components/ui/loading-button";
|
||||
import { CheckCircle2 } from "@lucide/svelte";
|
||||
import { CheckCircle2 } from "@lucide/svelte";
|
||||
import { api } from "$lib/api/client";
|
||||
import { ErrorAlert } from "$lib/components/auth";
|
||||
import { Alert, AlertDescription } from "$lib/components/ui/alert";
|
||||
import { Button } from "$lib/components/ui/button";
|
||||
import { Input } from "$lib/components/ui/input";
|
||||
import { Label } from "$lib/components/ui/label";
|
||||
import { LoadingButton } from "$lib/components/ui/loading-button";
|
||||
|
||||
// Form state
|
||||
let email = $state("");
|
||||
let isLoading = $state(false);
|
||||
let error = $state("");
|
||||
let isSubmitted = $state(false);
|
||||
// Form state
|
||||
let email = $state("");
|
||||
let isLoading = $state(false);
|
||||
let error = $state("");
|
||||
let isSubmitted = $state(false);
|
||||
|
||||
// Form validation
|
||||
const isFormValid = $derived(email.length > 0 && email.includes("@"));
|
||||
// Form validation
|
||||
const isFormValid = $derived(email.length > 0 && email.includes("@"));
|
||||
|
||||
async function handleSubmit(e: Event) {
|
||||
async function handleSubmit(e: Event) {
|
||||
e.preventDefault();
|
||||
if (!isFormValid) return;
|
||||
if (!isFormValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
isLoading = true;
|
||||
error = "";
|
||||
@@ -40,7 +42,7 @@
|
||||
} finally {
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
<script lang="ts">
|
||||
import { goto } from "$app/navigation";
|
||||
import { api } from "$lib/api/client";
|
||||
import { setLoginFlowState } from "$lib/stores/auth.svelte";
|
||||
import { ErrorAlert } from "$lib/components/auth";
|
||||
import { Input } from "$lib/components/ui/input";
|
||||
import { Label } from "$lib/components/ui/label";
|
||||
import { LoadingButton } from "$lib/components/ui/loading-button";
|
||||
import { goto } from "$app/navigation";
|
||||
import { api } from "$lib/api/client";
|
||||
import { ErrorAlert } from "$lib/components/auth";
|
||||
import { Input } from "$lib/components/ui/input";
|
||||
import { Label } from "$lib/components/ui/label";
|
||||
import { LoadingButton } from "$lib/components/ui/loading-button";
|
||||
import { setLoginFlowState } from "$lib/stores/auth.svelte";
|
||||
|
||||
let email = $state("");
|
||||
let isLoading = $state(false);
|
||||
let error = $state<string | null>(null);
|
||||
let email = $state("");
|
||||
let isLoading = $state(false);
|
||||
let error = $state<string | null>(null);
|
||||
|
||||
async function handleSubmit(e: SubmitEvent) {
|
||||
async function handleSubmit(e: SubmitEvent) {
|
||||
e.preventDefault();
|
||||
error = null;
|
||||
isLoading = true;
|
||||
@@ -32,7 +32,7 @@
|
||||
error = err instanceof Error ? err.message : "An unexpected error occurred";
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="space-y-6">
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { goto } from "$app/navigation";
|
||||
import { Fingerprint, KeyRound, Loader2 } from "@lucide/svelte";
|
||||
import { startAuthentication } from "@simplewebauthn/browser";
|
||||
import { goto } from "$app/navigation";
|
||||
import { api } from "$lib/api/client";
|
||||
import { ErrorAlert } from "$lib/components/auth";
|
||||
import { Button } from "$lib/components/ui/button";
|
||||
import { LoadingButton } from "$lib/components/ui/loading-button";
|
||||
import { api } from "$lib/api/client";
|
||||
import { loginFlowState, getMaskedEmail } from "$lib/stores/auth.svelte";
|
||||
import { Fingerprint, KeyRound, Loader2 } from "@lucide/svelte";
|
||||
import { getMaskedEmail, loginFlowState } from "$lib/stores/auth.svelte";
|
||||
|
||||
/**
|
||||
* Passkey authentication page
|
||||
@@ -32,7 +32,9 @@ async function authenticate(): Promise<void> {
|
||||
const options = await api.auth.webauthn.createAuthenticationOptions();
|
||||
|
||||
// Trigger browser WebAuthn prompt
|
||||
const credential = await startAuthentication({ optionsJSON: options.options });
|
||||
const credential = await startAuthentication({
|
||||
optionsJSON: options.options,
|
||||
});
|
||||
|
||||
// Verify with server
|
||||
await api.auth.webauthn.verifyAuthentication({
|
||||
@@ -60,7 +62,7 @@ $effect(() => {
|
||||
// Auto-trigger authentication on mount
|
||||
$effect(() => {
|
||||
if (loginFlowState.email && !hasAttempted) {
|
||||
authenticate();
|
||||
void authenticate();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
<script lang="ts">
|
||||
import { goto } from "$app/navigation";
|
||||
import { api } from "$lib/api/client";
|
||||
import { loginFlowState, clearLoginFlowState } from "$lib/stores/auth.svelte";
|
||||
import { Button } from "$lib/components/ui/button";
|
||||
import { Label } from "$lib/components/ui/label";
|
||||
import { PasswordInput, ErrorAlert } from "$lib/components/auth";
|
||||
import { LoadingButton } from "$lib/components/ui/loading-button";
|
||||
import { goto } from "$app/navigation";
|
||||
import { api } from "$lib/api/client";
|
||||
import { ErrorAlert, PasswordInput } from "$lib/components/auth";
|
||||
import { Button } from "$lib/components/ui/button";
|
||||
import { Label } from "$lib/components/ui/label";
|
||||
import { LoadingButton } from "$lib/components/ui/loading-button";
|
||||
import { clearLoginFlowState, loginFlowState } from "$lib/stores/auth.svelte";
|
||||
|
||||
let password = $state("");
|
||||
let isLoading = $state(false);
|
||||
let error = $state<string | null>(null);
|
||||
let password = $state("");
|
||||
let isLoading = $state(false);
|
||||
let error = $state<string | null>(null);
|
||||
|
||||
// Guard: redirect to /auth/login if no active login flow
|
||||
$effect(() => {
|
||||
// Guard: redirect to /auth/login if no active login flow
|
||||
$effect(() => {
|
||||
if (!loginFlowState.email) {
|
||||
goto("/auth/login");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
async function handleSubmit(e: SubmitEvent) {
|
||||
async function handleSubmit(e: SubmitEvent) {
|
||||
e.preventDefault();
|
||||
error = null;
|
||||
isLoading = true;
|
||||
@@ -28,15 +28,18 @@
|
||||
// On success, redirect to confirm page for email verification
|
||||
goto("/auth/confirm");
|
||||
} catch (err) {
|
||||
error = err instanceof Error ? err.message : "Invalid password. Please try again.";
|
||||
error =
|
||||
err instanceof Error
|
||||
? err.message
|
||||
: "Invalid password. Please try again.";
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleDifferentEmail() {
|
||||
function handleDifferentEmail() {
|
||||
clearLoginFlowState();
|
||||
goto("/auth/login");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="space-y-6">
|
||||
|
||||
@@ -1,38 +1,47 @@
|
||||
<script lang="ts">
|
||||
import { goto } from "$app/navigation";
|
||||
import { page } from "$app/stores";
|
||||
import { api } from "$lib/api/client";
|
||||
import { PasswordInput, PasswordStrength, ErrorAlert } from "$lib/components/auth";
|
||||
import { Alert, AlertDescription } from "$lib/components/ui/alert";
|
||||
import { Button } from "$lib/components/ui/button";
|
||||
import { Label } from "$lib/components/ui/label";
|
||||
import { LoadingButton } from "$lib/components/ui/loading-button";
|
||||
import { AlertCircle } from "@lucide/svelte";
|
||||
import { toast } from "svelte-sonner";
|
||||
import zxcvbn from "zxcvbn";
|
||||
import { AlertCircle } from "@lucide/svelte";
|
||||
import { toast } from "svelte-sonner";
|
||||
import zxcvbn from "zxcvbn";
|
||||
import { goto } from "$app/navigation";
|
||||
import { page } from "$app/stores";
|
||||
import { api } from "$lib/api/client";
|
||||
import {
|
||||
ErrorAlert,
|
||||
PasswordInput,
|
||||
PasswordStrength,
|
||||
} from "$lib/components/auth";
|
||||
import { Alert, AlertDescription } from "$lib/components/ui/alert";
|
||||
import { Button } from "$lib/components/ui/button";
|
||||
import { Label } from "$lib/components/ui/label";
|
||||
import { LoadingButton } from "$lib/components/ui/loading-button";
|
||||
|
||||
// Get token from URL
|
||||
const token = $derived($page.url.searchParams.get("token") ?? "");
|
||||
// Get token from URL
|
||||
const token = $derived($page.url.searchParams.get("token") ?? "");
|
||||
|
||||
// Form state
|
||||
let newPassword = $state("");
|
||||
let confirmPassword = $state("");
|
||||
let isLoading = $state(false);
|
||||
let error = $state("");
|
||||
// Form state
|
||||
let newPassword = $state("");
|
||||
let confirmPassword = $state("");
|
||||
let isLoading = $state(false);
|
||||
let error = $state("");
|
||||
|
||||
// Password validation
|
||||
const passwordScore = $derived(newPassword ? zxcvbn(newPassword).score : 0);
|
||||
const passwordsMatch = $derived(newPassword === confirmPassword);
|
||||
const isPasswordValid = $derived(
|
||||
newPassword.length >= 8 && passwordScore >= 3 && passwordsMatch && confirmPassword.length > 0
|
||||
);
|
||||
// Password validation
|
||||
const passwordScore = $derived(newPassword ? zxcvbn(newPassword).score : 0);
|
||||
const passwordsMatch = $derived(newPassword === confirmPassword);
|
||||
const isPasswordValid = $derived(
|
||||
newPassword.length >= 8 &&
|
||||
passwordScore >= 3 &&
|
||||
passwordsMatch &&
|
||||
confirmPassword.length > 0,
|
||||
);
|
||||
|
||||
// Form validation
|
||||
const isFormValid = $derived(token.length > 0 && isPasswordValid);
|
||||
// Form validation
|
||||
const isFormValid = $derived(token.length > 0 && isPasswordValid);
|
||||
|
||||
async function handleSubmit(e: Event) {
|
||||
async function handleSubmit(e: Event) {
|
||||
e.preventDefault();
|
||||
if (!isFormValid) return;
|
||||
if (!isFormValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
isLoading = true;
|
||||
error = "";
|
||||
@@ -52,7 +61,8 @@
|
||||
if (err instanceof Error) {
|
||||
// Handle specific error cases
|
||||
if (err.message.includes("expired") || err.message.includes("invalid")) {
|
||||
error = "This password reset link has expired or is invalid. Please request a new one.";
|
||||
error =
|
||||
"This password reset link has expired or is invalid. Please request a new one.";
|
||||
} else {
|
||||
error = err.message;
|
||||
}
|
||||
@@ -62,7 +72,7 @@
|
||||
} finally {
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
<script lang="ts">
|
||||
import { goto } from "$app/navigation";
|
||||
import { api } from "$lib/api/client";
|
||||
import { ErrorAlert } from "$lib/components/auth";
|
||||
import { Button } from "$lib/components/ui/button";
|
||||
import { Input } from "$lib/components/ui/input";
|
||||
import { Label } from "$lib/components/ui/label";
|
||||
import { Alert, AlertDescription } from "$lib/components/ui/alert";
|
||||
import { LoadingButton } from "$lib/components/ui/loading-button";
|
||||
import { AlertCircle, Loader2 } from "@lucide/svelte";
|
||||
import { createQuery } from "@tanstack/svelte-query";
|
||||
import { toast } from "svelte-sonner";
|
||||
import { validatePhone } from "$lib/utils/validation";
|
||||
import { AlertCircle, Loader2 } from "@lucide/svelte";
|
||||
import { createQuery } from "@tanstack/svelte-query";
|
||||
import { toast } from "svelte-sonner";
|
||||
import { goto } from "$app/navigation";
|
||||
import { api } from "$lib/api/client";
|
||||
import { ErrorAlert } from "$lib/components/auth";
|
||||
import { Alert, AlertDescription } from "$lib/components/ui/alert";
|
||||
import { Button } from "$lib/components/ui/button";
|
||||
import { Input } from "$lib/components/ui/input";
|
||||
import { Label } from "$lib/components/ui/label";
|
||||
import { LoadingButton } from "$lib/components/ui/loading-button";
|
||||
import { validatePhone } from "$lib/utils/validation";
|
||||
|
||||
// Fetch current user to check if setup is needed
|
||||
// TanStack Query v6 with Svelte 5: options passed as thunk, results accessed directly
|
||||
const userQuery = createQuery(() => ({
|
||||
// Fetch current user to check if setup is needed
|
||||
// TanStack Query v6 with Svelte 5: options passed as thunk, results accessed directly
|
||||
const userQuery = createQuery(() => ({
|
||||
queryKey: ["me"],
|
||||
queryFn: () => api.me.get(),
|
||||
}));
|
||||
}));
|
||||
|
||||
// Redirect if user doesn't need setup
|
||||
$effect(() => {
|
||||
// Redirect if user doesn't need setup
|
||||
$effect(() => {
|
||||
if (userQuery.data && !userQuery.data.needsSetup) {
|
||||
goto("/performance");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
let displayName = $state("");
|
||||
let fullName = $state("");
|
||||
let phoneNumber = $state("");
|
||||
let isSubmitting = $state(false);
|
||||
let error = $state("");
|
||||
let phoneError = $state("");
|
||||
let displayName = $state("");
|
||||
let fullName = $state("");
|
||||
let phoneNumber = $state("");
|
||||
let isSubmitting = $state(false);
|
||||
let error = $state("");
|
||||
let phoneError = $state("");
|
||||
|
||||
function handlePhoneBlur() {
|
||||
function handlePhoneBlur() {
|
||||
const result = validatePhone(phoneNumber);
|
||||
if (phoneNumber && !result.valid) {
|
||||
phoneError = "Please enter a valid phone number (e.g., +1 555 123 4567)";
|
||||
@@ -43,17 +43,19 @@
|
||||
phoneNumber = result.formatted;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const isValid = $derived(
|
||||
const isValid = $derived(
|
||||
displayName.trim().length >= 1 &&
|
||||
displayName.trim().length <= 100 &&
|
||||
(!phoneNumber || validatePhone(phoneNumber).valid)
|
||||
);
|
||||
(!phoneNumber || validatePhone(phoneNumber).valid),
|
||||
);
|
||||
|
||||
async function handleSubmit(e: Event) {
|
||||
async function handleSubmit(e: Event) {
|
||||
e.preventDefault();
|
||||
if (!isValid || isSubmitting) return;
|
||||
if (!isValid || isSubmitting) {
|
||||
return;
|
||||
}
|
||||
|
||||
isSubmitting = true;
|
||||
error = "";
|
||||
@@ -72,7 +74,7 @@
|
||||
} finally {
|
||||
isSubmitting = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
|
||||
@@ -1,56 +1,69 @@
|
||||
<script lang="ts">
|
||||
import { goto } from "$app/navigation";
|
||||
import { api } from "$lib/api/client";
|
||||
import { PasswordInput, PasswordStrength, ErrorAlert } from "$lib/components/auth";
|
||||
import { Input } from "$lib/components/ui/input";
|
||||
import { Label } from "$lib/components/ui/label";
|
||||
import { LoadingButton } from "$lib/components/ui/loading-button";
|
||||
import { browserSupportsWebAuthn, startRegistration } from "@simplewebauthn/browser";
|
||||
import zxcvbn from "zxcvbn";
|
||||
import {
|
||||
browserSupportsWebAuthn,
|
||||
startRegistration,
|
||||
} from "@simplewebauthn/browser";
|
||||
import zxcvbn from "zxcvbn";
|
||||
import { goto } from "$app/navigation";
|
||||
import { api } from "$lib/api/client";
|
||||
import {
|
||||
ErrorAlert,
|
||||
PasswordInput,
|
||||
PasswordStrength,
|
||||
} from "$lib/components/auth";
|
||||
import { Input } from "$lib/components/ui/input";
|
||||
import { Label } from "$lib/components/ui/label";
|
||||
import { LoadingButton } from "$lib/components/ui/loading-button";
|
||||
|
||||
// Form state
|
||||
let email = $state("");
|
||||
let password = $state("");
|
||||
let confirmPassword = $state("");
|
||||
let isLoading = $state(false);
|
||||
let error = $state("");
|
||||
// Form state
|
||||
let email = $state("");
|
||||
let password = $state("");
|
||||
let confirmPassword = $state("");
|
||||
let isLoading = $state(false);
|
||||
let error = $state("");
|
||||
|
||||
// Authentication mode: "passkey" or "password"
|
||||
let authMode = $state<"passkey" | "password">("passkey");
|
||||
// Authentication mode: "passkey" or "password"
|
||||
let authMode = $state<"passkey" | "password">("passkey");
|
||||
|
||||
// Check passkey support on mount
|
||||
let supportsPasskey = $state(false);
|
||||
$effect(() => {
|
||||
// Check passkey support on mount
|
||||
let supportsPasskey = $state(false);
|
||||
$effect(() => {
|
||||
supportsPasskey = browserSupportsWebAuthn();
|
||||
if (!supportsPasskey) {
|
||||
authMode = "password";
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Password validation
|
||||
const passwordScore = $derived(password ? zxcvbn(password, [email]).score : 0);
|
||||
const passwordsMatch = $derived(password === confirmPassword);
|
||||
const isPasswordValid = $derived(
|
||||
password.length >= 8 && passwordScore >= 3 && passwordsMatch && confirmPassword.length > 0
|
||||
);
|
||||
// Password validation
|
||||
const passwordScore = $derived(password ? zxcvbn(password, [email]).score : 0);
|
||||
const passwordsMatch = $derived(password === confirmPassword);
|
||||
const isPasswordValid = $derived(
|
||||
password.length >= 8 &&
|
||||
passwordScore >= 3 &&
|
||||
passwordsMatch &&
|
||||
confirmPassword.length > 0,
|
||||
);
|
||||
|
||||
// Form validation
|
||||
const isFormValid = $derived(
|
||||
// Form validation
|
||||
const isFormValid = $derived(
|
||||
authMode === "passkey"
|
||||
? email.length > 0 && email.includes("@")
|
||||
: email.length > 0 && email.includes("@") && isPasswordValid
|
||||
);
|
||||
: email.length > 0 && email.includes("@") && isPasswordValid,
|
||||
);
|
||||
|
||||
async function handlePasskeySignup() {
|
||||
async function handlePasskeySignup() {
|
||||
isLoading = true;
|
||||
error = "";
|
||||
|
||||
try {
|
||||
// Step 1: Get registration options from server
|
||||
const { challengeId, options } = await api.auth.webauthn.createRegistrationOptions({ email });
|
||||
const { challengeId, options } =
|
||||
await api.auth.webauthn.createRegistrationOptions({ email });
|
||||
|
||||
// Step 2: Start WebAuthn registration
|
||||
const registrationResponse = await startRegistration({ optionsJSON: options });
|
||||
const registrationResponse = await startRegistration({
|
||||
optionsJSON: options,
|
||||
});
|
||||
|
||||
// Step 3: Complete signup with passkey info
|
||||
await api.auth.signup({
|
||||
@@ -77,9 +90,9 @@
|
||||
} finally {
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function handlePasswordSignup() {
|
||||
async function handlePasswordSignup() {
|
||||
isLoading = true;
|
||||
error = "";
|
||||
|
||||
@@ -100,28 +113,30 @@
|
||||
} finally {
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSubmit(e: Event) {
|
||||
async function handleSubmit(e: Event) {
|
||||
e.preventDefault();
|
||||
if (!isFormValid) return;
|
||||
if (!isFormValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (authMode === "passkey") {
|
||||
await handlePasskeySignup();
|
||||
} else {
|
||||
await handlePasswordSignup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function switchToPassword() {
|
||||
function switchToPassword() {
|
||||
authMode = "password";
|
||||
}
|
||||
}
|
||||
|
||||
function switchToPasskey() {
|
||||
function switchToPasskey() {
|
||||
authMode = "passkey";
|
||||
password = "";
|
||||
confirmPassword = "";
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
|
||||
@@ -1,46 +1,50 @@
|
||||
<script lang="ts">
|
||||
import { goto } from "$app/navigation";
|
||||
import { api } from "$lib/api/client";
|
||||
import { ErrorAlert } from "$lib/components/auth";
|
||||
import { Button } from "$lib/components/ui/button";
|
||||
import { Input } from "$lib/components/ui/input";
|
||||
import { Label } from "$lib/components/ui/label";
|
||||
import { LoadingButton } from "$lib/components/ui/loading-button";
|
||||
import { Monitor, Smartphone, Tablet, Shield, MapPin } from "@lucide/svelte";
|
||||
import { createQuery } from "@tanstack/svelte-query";
|
||||
import { toast } from "svelte-sonner";
|
||||
import { UAParser } from "ua-parser-js";
|
||||
import { MapPin, Monitor, Shield, Smartphone, Tablet } from "@lucide/svelte";
|
||||
import { createQuery } from "@tanstack/svelte-query";
|
||||
import { toast } from "svelte-sonner";
|
||||
import { UAParser } from "ua-parser-js";
|
||||
import { goto } from "$app/navigation";
|
||||
import { api } from "$lib/api/client";
|
||||
import { ErrorAlert } from "$lib/components/auth";
|
||||
import { Button } from "$lib/components/ui/button";
|
||||
import { Input } from "$lib/components/ui/input";
|
||||
import { Label } from "$lib/components/ui/label";
|
||||
import { LoadingButton } from "$lib/components/ui/loading-button";
|
||||
|
||||
// Fetch device info from server
|
||||
// TanStack Query v6 with Svelte 5: options passed as thunk, results accessed directly
|
||||
const deviceQuery = createQuery(() => ({
|
||||
// Fetch device info from server
|
||||
// TanStack Query v6 with Svelte 5: options passed as thunk, results accessed directly
|
||||
const deviceQuery = createQuery(() => ({
|
||||
queryKey: ["deviceInfo"],
|
||||
queryFn: () => api.me.getDeviceInfo(),
|
||||
}));
|
||||
}));
|
||||
|
||||
// Parse user agent for suggested device name
|
||||
const parser = new UAParser(navigator.userAgent);
|
||||
const browserName = parser.getBrowser().name || "Browser";
|
||||
const osName = parser.getOS().name || "Device";
|
||||
const deviceType = parser.getDevice().type;
|
||||
// Parse user agent for suggested device name
|
||||
const parser = new UAParser(navigator.userAgent);
|
||||
const browserName = parser.getBrowser().name || "Browser";
|
||||
const osName = parser.getOS().name || "Device";
|
||||
const deviceType = parser.getDevice().type;
|
||||
|
||||
const suggestedName = $derived(`${browserName} on ${osName}`);
|
||||
const suggestedName = $derived(`${browserName} on ${osName}`);
|
||||
|
||||
let deviceName = $state("");
|
||||
let isSubmitting = $state(false);
|
||||
let error = $state("");
|
||||
let deviceName = $state("");
|
||||
let isSubmitting = $state(false);
|
||||
let error = $state("");
|
||||
|
||||
// Initialize device name with suggestion
|
||||
$effect(() => {
|
||||
// Initialize device name with suggestion
|
||||
$effect(() => {
|
||||
if (!deviceName && suggestedName) {
|
||||
deviceName = suggestedName;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const isValid = $derived(deviceName.trim().length >= 1 && deviceName.trim().length <= 100);
|
||||
const isValid = $derived(
|
||||
deviceName.trim().length >= 1 && deviceName.trim().length <= 100,
|
||||
);
|
||||
|
||||
async function handleTrust() {
|
||||
if (!isValid || isSubmitting) return;
|
||||
async function handleTrust() {
|
||||
if (!isValid || isSubmitting) {
|
||||
return;
|
||||
}
|
||||
|
||||
isSubmitting = true;
|
||||
error = "";
|
||||
@@ -54,14 +58,14 @@
|
||||
} finally {
|
||||
isSubmitting = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSkip() {
|
||||
async function handleSkip() {
|
||||
goto("/performance");
|
||||
}
|
||||
}
|
||||
|
||||
// Get device icon based on type
|
||||
function getDeviceIcon() {
|
||||
// Get device icon based on type
|
||||
function getDeviceIcon() {
|
||||
switch (deviceType) {
|
||||
case "mobile":
|
||||
return Smartphone;
|
||||
@@ -70,9 +74,9 @@
|
||||
default:
|
||||
return Monitor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const DeviceIcon = getDeviceIcon();
|
||||
const DeviceIcon = getDeviceIcon();
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { page } from "$app/state";
|
||||
import { goto } from "$app/navigation";
|
||||
import { CheckCircle2, Loader2, Mail, XCircle } from "@lucide/svelte";
|
||||
import { toast } from "svelte-sonner";
|
||||
import { goto } from "$app/navigation";
|
||||
import { page } from "$app/state";
|
||||
import { api } from "$lib/api/client";
|
||||
import { ErrorAlert } from "$lib/components/auth";
|
||||
import { Button } from "$lib/components/ui/button";
|
||||
import { api } from "$lib/api/client";
|
||||
import { Mail, XCircle, CheckCircle2, Loader2 } from "@lucide/svelte";
|
||||
|
||||
/**
|
||||
* Email verification callback page
|
||||
@@ -42,7 +42,7 @@ async function verifyEmail(): Promise<void> {
|
||||
// Auto-verify on mount
|
||||
$effect(() => {
|
||||
if (token) {
|
||||
verifyEmail();
|
||||
void verifyEmail();
|
||||
} else {
|
||||
error = "No verification token provided";
|
||||
isVerifying = false;
|
||||
@@ -58,7 +58,8 @@ async function resendVerification(): Promise<void> {
|
||||
toast.success("Verification email sent! Check your inbox.");
|
||||
error = "";
|
||||
} catch (e) {
|
||||
const message = e instanceof Error ? e.message : "Failed to send verification email";
|
||||
const message =
|
||||
e instanceof Error ? e.message : "Failed to send verification email";
|
||||
toast.error(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<script lang="ts">
|
||||
import { goto } from "$app/navigation";
|
||||
import { goto } from "$app/navigation";
|
||||
|
||||
// Redirect old /login route to new /auth/login
|
||||
$effect(() => {
|
||||
// Redirect old /login route to new /auth/login
|
||||
$effect(() => {
|
||||
goto("/auth/login", { replaceState: true });
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="flex min-h-screen items-center justify-center">
|
||||
|
||||
Reference in New Issue
Block a user