Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

refactor(web): unify auth flow, remove sign-up page

Gener361f8de13fa9
diff --git a/src/web/src/app/(auth)/sign-in/page.tsx b/src/web/src/app/(auth)/sign-in/page.tsx
index b59df25ad..fec0026ae 100644
--- a/src/web/src/app/(auth)/sign-in/page.tsx
+++ b/src/web/src/app/(auth)/sign-in/page.tsx
@@ -1,7 +1,7 @@
"use client"
import { useState } from "react"
-import { signIn, authClient } from "@/lib/auth-client"
+import { signIn, signUp, authClient } from "@/lib/auth-client"
import { Button } from "@/components/ui/button"
import { Card, CardContent } from "@/components/ui/card"
import { Input } from "@/components/ui/input"
@@ -12,7 +12,6 @@ import {
} from "@/components/ui/input-otp"
import {
Field,
- FieldDescription,
FieldError,
FieldGroup,
FieldLabel,
@@ -58,7 +57,7 @@ function OTPSignIn() {
setError("")
setLoading(true)
try {
- const { error } = await authClient.emailOtp.verifyEmail({
+ const { error } = await authClient.signIn.emailOtp({
email,
otp: value,
})
@@ -184,17 +183,23 @@ function PasswordSignIn() {
e.preventDefault()
setError("")
setLoading(true)
- const { error } = await signIn.email(
+ const { error: signInErr } = await signIn.email(
{ email, password },
- { onError: (ctx) => setError(ctx.error.message) },
+ { onError: () => {} },
)
- if (error) {
- setError(error.message ?? "")
- } else {
- window.location.href = "/workspaces?auto"
- return
+ if (signInErr) {
+ // Sign-in failed — try auto sign-up
+ const { error: signUpErr } = await signUp.email(
+ { name: email.split("@")[0], email, password },
+ { onError: () => {} },
+ )
+ if (signUpErr) {
+ setError(signInErr.message ?? "Invalid email or password")
+ setLoading(false)
+ return
+ }
}
- setLoading(false)
+ window.location.href = "/workspaces?auto"
}
return (
@@ -258,10 +263,6 @@ function PasswordSignIn() {
Google
</Button>
</Field>
- <FieldDescription className="text-center">
- Don&apos;t have an account?{" "}
- <a href="/sign-up">Sign up</a>
- </FieldDescription>
</FieldGroup>
</form>
)
diff --git a/src/web/src/app/(auth)/sign-up/page.tsx b/src/web/src/app/(auth)/sign-up/page.tsx
deleted file mode 100644
index 3d5590829..000000000
--- a/src/web/src/app/(auth)/sign-up/page.tsx
+++ /dev/null
@@ -1,110 +0,0 @@
-"use client"
-
-import { useState } from "react"
-import { redirect } from "next/navigation"
-import { signUp } from "@/lib/auth-client"
-import { Button } from "@/components/ui/button"
-import { Card, CardContent } from "@/components/ui/card"
-import { Input } from "@/components/ui/input"
-import {
- Field,
- FieldDescription,
- FieldError,
- FieldGroup,
- FieldLabel,
-} from "@/components/ui/field"
-import { GradientBackground } from "@/components/gradient-background"
-import { TypewriterVisual } from "@/components/typewriter-visual"
-
-const isProd = process.env.NEXTJS_ENV === "production"
-
-function SignUpForm() {
- const [email, setEmail] = useState("")
- const [password, setPassword] = useState("")
- const [error, setError] = useState("")
- const [loading, setLoading] = useState(false)
-
- async function handleSubmit(e: React.FormEvent) {
- e.preventDefault()
- setError("")
- setLoading(true)
- const { error } = await signUp.email(
- { name: "", email, password },
- { onError: (ctx) => setError(ctx.error.message) },
- )
- if (error) {
- setError(error.message ?? "")
- } else {
- window.location.href = "/workspaces?auto"
- return
- }
- setLoading(false)
- }
-
- return (
- <div className="relative flex min-h-svh flex-col items-center justify-center p-6 md:p-10">
- <GradientBackground />
- <div className="w-full max-w-sm md:max-w-4xl">
- <div className="flex flex-col gap-6">
- <Card className="overflow-hidden p-0">
- <CardContent className="grid p-0 md:grid-cols-2">
- <form className="p-6 md:p-8" onSubmit={handleSubmit}>
- <FieldGroup>
- <div className="flex flex-col items-center gap-2 text-center">
- <h1 className="text-2xl font-bold">Create your account</h1>
- <p className="text-balance text-muted-foreground">
- Get started with Alook
- </p>
- </div>
- {error && (
- <FieldError>{error}</FieldError>
- )}
- <Field>
- <FieldLabel htmlFor="email">Email</FieldLabel>
- <Input
- id="email"
- type="email"
- placeholder="[email protected]"
- value={email}
- onChange={(e) => setEmail(e.target.value)}
- required
- />
- </Field>
- <Field>
- <FieldLabel htmlFor="password">Password</FieldLabel>
- <Input
- id="password"
- type="password"
- placeholder="At least 8 characters"
- value={password}
- onChange={(e) => setPassword(e.target.value)}
- required
- minLength={8}
- />
- </Field>
- <Field>
- <Button type="submit" disabled={loading} className="w-full">
- {loading ? "Creating account..." : "Create account"}
- </Button>
- </Field>
- <FieldDescription className="text-center">
- Already have an account?{" "}
- <a href="/sign-in">Sign in</a>
- </FieldDescription>
- </FieldGroup>
- </form>
- <div className="relative hidden bg-muted md:block overflow-hidden">
- <TypewriterVisual className="h-full scale-[0.6] origin-center" />
- </div>
- </CardContent>
- </Card>
- </div>
- </div>
- </div>
- )
-}
-
-export default function SignUpPage() {
- if (isProd) redirect("/sign-in")
- return <SignUpForm />
-}