Files
aurora-moments/web/src/pages/RegisterPage.tsx
T
KrisandClaude Sonnet 5 4877e0a779 Initial commit: Aurora Moments self-hosted photo/video sharing platform
Django/DRF + PostgreSQL/Redis/Celery backend with accounts, library,
moments, and notifications apps; React/TypeScript/Vite frontend with
Instagram-style sidebar nav, feed, profiles, nested comment replies,
notifications, and photo/video upload with ffmpeg-generated posters.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
2026-08-10 10:28:53 -05:00

64 lines
1.9 KiB
TypeScript

import { useState } from 'react'
import type { FormEvent } from 'react'
import { Link, useNavigate } from 'react-router-dom'
import { ApiError } from '../api/client'
import { useAuth } from '../context/AuthContext'
export function RegisterPage() {
const { register } = useAuth()
const navigate = useNavigate()
const [email, setEmail] = useState('')
const [username, setUsername] = useState('')
const [password, setPassword] = useState('')
const [error, setError] = useState<string | null>(null)
const [submitting, setSubmitting] = useState(false)
const handleSubmit = async (event: FormEvent) => {
event.preventDefault()
setError(null)
setSubmitting(true)
try {
await register(email, username, password)
navigate('/')
} catch (err) {
if (err instanceof ApiError) {
setError(JSON.stringify(err.body))
} else {
setError('Could not create account.')
}
} finally {
setSubmitting(false)
}
}
return (
<div className="auth-page">
<form className="auth-form" onSubmit={handleSubmit}>
<h1>Create your account</h1>
<input type="email" placeholder="Email" value={email} onChange={(e) => setEmail(e.target.value)} required />
<input
type="text"
placeholder="Username"
value={username}
onChange={(e) => setUsername(e.target.value)}
required
/>
<input
type="password"
placeholder="Password"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
/>
{error && <p className="auth-error">{error}</p>}
<button type="submit" disabled={submitting}>
{submitting ? 'Creating…' : 'Create account'}
</button>
<p>
Already have an account? <Link to="/login">Sign in</Link>
</p>
</form>
</div>
)
}