From 60100e9c521a040a34207a2c86ce44f5b8b26411 Mon Sep 17 00:00:00 2001 From: v0 Date: Sun, 22 Mar 2026 23:38:40 +0000 Subject: [PATCH] revert passkey support and restore pre-passkey state Co-authored-by: ASOwnerYT <23545044+ASOwnerYT@users.noreply.github.com> --- app/auth/login/page.tsx | 52 +--------- app/dashboard/page.tsx | 55 +++++------ components/passkey-manager.tsx | 137 -------------------------- lib/passkeys.ts | 83 ---------------- scripts/001_create_passkeys_table.sql | 35 ------- 5 files changed, 24 insertions(+), 338 deletions(-) delete mode 100644 components/passkey-manager.tsx delete mode 100644 lib/passkeys.ts delete mode 100644 scripts/001_create_passkeys_table.sql diff --git a/app/auth/login/page.tsx b/app/auth/login/page.tsx index 452a0fa..2c95e9d 100644 --- a/app/auth/login/page.tsx +++ b/app/auth/login/page.tsx @@ -7,8 +7,7 @@ import { Label } from '@/components/ui/label' import Link from 'next/link' import { useRouter } from 'next/navigation' import { useState } from 'react' -import { Mail, Lock, Loader2, ArrowLeft, Key } from 'lucide-react' -import { isPasskeySupported, authenticateWithPasskey } from '@/lib/passkeys' +import { Mail, Lock, Loader2, ArrowLeft } from 'lucide-react' export default function LoginPage() { const [email, setEmail] = useState('') @@ -16,8 +15,6 @@ export default function LoginPage() { const [error, setError] = useState(null) const [isLoading, setIsLoading] = useState(false) const [isGoogleLoading, setIsGoogleLoading] = useState(false) - const [isPasskeyLoading, setIsPasskeyLoading] = useState(false) - const [passkeySupported] = useState(() => isPasskeySupported()) const router = useRouter() const handleLogin = async (e: React.FormEvent) => { @@ -59,33 +56,6 @@ export default function LoginPage() { } } - const handlePasskeyLogin = async () => { - const supabase = createClient() - setIsPasskeyLoading(true) - setError(null) - - try { - const credential = await authenticateWithPasskey() - - if (!credential) { - throw new Error('Passkey authentication failed') - } - - // For now, passkeys are registered as a factor in Supabase - // This is a placeholder - in production, you'd verify the credential server-side - console.log('[v0] Passkey authentication initiated:', credential.id) - - // Since this is invite-only, users would have pre-registered their passkeys - // and we'd verify them here. For now, show success. - setError('Passkey authentication requires server-side verification setup') - } catch (error: unknown) { - const message = error instanceof Error ? error.message : 'Passkey authentication failed' - setError(message) - } finally { - setIsPasskeyLoading(false) - } - } - return (
{/* Background elements */} @@ -119,26 +89,6 @@ export default function LoginPage() {

- {/* Passkey Button */} - {passkeySupported && ( - - )} - {/* Google OAuth Button */} - - - {error && ( -
-

{error}

-
- )} - - {success && ( -
-

{success}

-
- )} - - {passkeys.length === 0 ? ( -
- -

- No passkeys registered yet. Add one to enable passwordless sign-in. -

-
- ) : ( -
- {passkeys.map((passkey) => ( -
-
-

{passkey.name}

-

- Added on {passkey.createdAt} -

-
- -
- ))} -
- )} - - ) -} diff --git a/lib/passkeys.ts b/lib/passkeys.ts deleted file mode 100644 index 219ee6e..0000000 --- a/lib/passkeys.ts +++ /dev/null @@ -1,83 +0,0 @@ -'use client' - -import { createClient } from '@/lib/supabase/client' - -export async function registerPasskey(userId: string, displayName: string) { - const supabase = createClient() - - if (!window.PublicKeyCredential) { - throw new Error('Passkeys are not supported in your browser') - } - - try { - // Get registration options from Supabase - const { data, error } = await supabase.auth.signInWithEnrollFactors({ - factorType: 'totp', - }) - - if (error) throw error - - // For now, we'll use a simplified approach with browser's WebAuthn API - // Create a passkey credential - const credential = await navigator.credentials.create({ - publicKey: { - challenge: new Uint8Array(32), - rp: { - name: 'Cloudrite', - id: window.location.hostname, - }, - user: { - id: new TextEncoder().encode(userId), - name: userId, - displayName: displayName, - }, - pubKeyCredParams: [{ type: 'public-key', alg: -7 }], - timeout: 60000, - attestation: 'direct', - }, - }) as PublicKeyCredential | null - - if (!credential) { - throw new Error('Failed to create passkey') - } - - return credential - } catch (error) { - console.error('[v0] Passkey registration failed:', error) - throw error - } -} - -export async function authenticateWithPasskey() { - if (!window.PublicKeyCredential) { - throw new Error('Passkeys are not supported in your browser') - } - - try { - const assertion = await navigator.credentials.get({ - publicKey: { - challenge: new Uint8Array(32), - timeout: 60000, - userVerification: 'preferred', - }, - }) as PublicKeyCredential | null - - if (!assertion) { - throw new Error('Passkey authentication cancelled or failed') - } - - return assertion - } catch (error) { - console.error('[v0] Passkey authentication failed:', error) - throw error - } -} - -export function isPasskeySupported(): boolean { - return !!( - window.PublicKeyCredential && - navigator.credentials && - navigator.credentials.create && - navigator.credentials.get - ) -} diff --git a/scripts/001_create_passkeys_table.sql b/scripts/001_create_passkeys_table.sql deleted file mode 100644 index bc3addc..0000000 --- a/scripts/001_create_passkeys_table.sql +++ /dev/null @@ -1,35 +0,0 @@ --- Create passkeys table for WebAuthn credential storage -CREATE TABLE IF NOT EXISTS public.passkeys ( - id UUID PRIMARY KEY DEFAULT gen_random_uuid(), - user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE, - credential_id TEXT NOT NULL UNIQUE, - public_key TEXT NOT NULL, - sign_count INTEGER NOT NULL DEFAULT 0, - transports TEXT[] DEFAULT ARRAY[]::TEXT[], - backup_eligible BOOLEAN DEFAULT FALSE, - backup_state BOOLEAN DEFAULT FALSE, - aaguid UUID, - created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, - last_used TIMESTAMP WITH TIME ZONE, - friendly_name TEXT -); - --- Enable RLS on passkeys table -ALTER TABLE public.passkeys ENABLE ROW LEVEL SECURITY; - --- Create RLS policies for passkeys -CREATE POLICY "Users can view their own passkeys" ON public.passkeys - FOR SELECT USING (auth.uid() = user_id); - -CREATE POLICY "Users can insert their own passkeys" ON public.passkeys - FOR INSERT WITH CHECK (auth.uid() = user_id); - -CREATE POLICY "Users can delete their own passkeys" ON public.passkeys - FOR DELETE USING (auth.uid() = user_id); - -CREATE POLICY "Users can update their own passkeys" ON public.passkeys - FOR UPDATE USING (auth.uid() = user_id); - --- Create index for faster credential lookups -CREATE INDEX idx_passkeys_credential_id ON public.passkeys(credential_id); -CREATE INDEX idx_passkeys_user_id ON public.passkeys(user_id);