Skip to content

Commit

Permalink
refactor(frontend): Auth pages update (#9124)
Browse files Browse the repository at this point in the history
There are UX and design issues with current auth pages; `login`,
`signup` and `reset_password` (including change password).

### Changes 🏗️


![auth](https://github.com/user-attachments/assets/56dfbae3-5c12-4324-a29a-846d091d9501)
*Missing `s` on the login's password error is fixed.

Important changes in bold.

#### All auth pages
- **Split `/login` into `/signup`**
- UI Redesign that adheres to Figma designs
- General code cleanup and improvements
- Fix feedback: it's now shown when needed and clear (e.g. "~~String~~
Password must be...")
- All action functions use `Sentry.withServerActionInstrumentation`
- `PasswordInput` "eye button" shows password only when mouse button is
hold and doesn't capture tab

#### Login page
- **Removed agree to terms checkbox** (it's only on signup now)
- Move provider login function to `actions.ts`

#### Signup page
- **Requires to type password twice**
- Shows waitlist information on *any* database error

#### Reset password page
- **Password update requires to type password twice**
- **When request to send email is processed then the feedback is:
Password reset email sent if user exists. Please check your email.**
- Email sent feedback is black, error is red
- Move send email and update password functions to `actions.ts`
- Disable button when email is sent

#### Other
- Update zod schema objects and move them to `types/auth`
- Move `components/PasswordInput.tsx` to `/components/auth`
- Make common UI elements separate components in `components/auth`
- Update `yarn.lock` (supabase packages)
- Remove redundant letter in `client.ts`
- Don't log error when user auth is missing in `useSupabase`; user is
simply not logged in

### Checklist 📋

#### For code changes:
- [x] I have clearly listed my changes in the PR description
- [x] I have made a test plan
- [x] I have tested my changes according to the test plan:
  - [x] Form feedback:
    - [x] Login works
    - [x] Signup works
    - [x] Reset email works
    - [x] Change password works
  - [x] Login works
  - [x] Signup works
  - [x] Reset email is sent
  - [x] Reset email logs user in and redirects to `/reset_password`
  - [x] Change password works
  - [x] Logout works
  - [x] All links across auth pages work

Note: OAuth login providers are disabled and so untested.

<details>
  <summary>Example test plan</summary>
  
  - [ ] Create from scratch and execute an agent with at least 3 blocks
- [ ] Import an agent from file upload, and confirm it executes
correctly
  - [ ] Upload agent to marketplace
- [ ] Import an agent from marketplace and confirm it executes correctly
  - [ ] Edit an agent from monitor, and confirm it executes correctly
</details>

#### For configuration changes:
- [ ] `.env.example` is updated or already compatible with my changes
- [ ] `docker-compose.yml` is updated or already compatible with my
changes
- [ ] I have included a list of my configuration changes in the PR
description (under **Changes**)

<details>
  <summary>Examples of configuration changes</summary>

  - Changing ports
  - Adding new services that need to communicate with each other
  - Secrets or environment variable changes
  - New or infrastructure changes such as databases
</details>

---------

Co-authored-by: Zamil Majdy <[email protected]>
  • Loading branch information
kcze and majdyz authored Dec 30, 2024
1 parent 763284e commit 15af2f4
Show file tree
Hide file tree
Showing 17 changed files with 804 additions and 416 deletions.
51 changes: 19 additions & 32 deletions autogpt_platform/frontend/src/app/login/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import { z } from "zod";
import * as Sentry from "@sentry/nextjs";
import getServerSupabase from "@/lib/supabase/getServerSupabase";
import BackendAPI from "@/lib/autogpt-server-api";

const loginFormSchema = z.object({
email: z.string().email().min(2).max(64),
password: z.string().min(6).max(64),
});
import { loginFormSchema, LoginProvider } from "@/types/auth";

export async function logout() {
return await Sentry.withServerActionInstrumentation(
Expand All @@ -25,7 +21,7 @@ export async function logout() {
const { error } = await supabase.auth.signOut();

if (error) {
console.log("Error logging out", error);
console.error("Error logging out", error);
return error.message;
}

Expand All @@ -47,18 +43,13 @@ export async function login(values: z.infer<typeof loginFormSchema>) {
// We are sure that the values are of the correct type because zod validates the form
const { data, error } = await supabase.auth.signInWithPassword(values);

await api.createUser();

if (error) {
console.log("Error logging in", error);
if (error.status == 400) {
// Hence User is not present
redirect("/login");
}

console.error("Error logging in", error);
return error.message;
}

await api.createUser();

if (data.session) {
await supabase.auth.setSession(data.session);
}
Expand All @@ -68,38 +59,34 @@ export async function login(values: z.infer<typeof loginFormSchema>) {
});
}

export async function signup(values: z.infer<typeof loginFormSchema>) {
"use server";
export async function providerLogin(provider: LoginProvider) {
return await Sentry.withServerActionInstrumentation(
"signup",
"providerLogin",
{},
async () => {
const supabase = getServerSupabase();
const api = new BackendAPI();

if (!supabase) {
redirect("/error");
}

// We are sure that the values are of the correct type because zod validates the form
const { data, error } = await supabase.auth.signUp(values);
const { error } = await supabase!.auth.signInWithOAuth({
provider: provider,
options: {
redirectTo:
process.env.AUTH_CALLBACK_URL ??
`http://localhost:3000/auth/callback`,
},
});

if (error) {
console.log("Error signing up", error);
if (error.message.includes("P0001")) {
return "Please join our waitlist for your turn: https://agpt.co/waitlist";
}
if (error.code?.includes("user_already_exists")) {
redirect("/login");
}
console.error("Error logging in", error);
return error.message;
}

if (data.session) {
await supabase.auth.setSession(data.session);
}
console.log("Signed up");
revalidatePath("/", "layout");
redirect("/store/profile");
await api.createUser();
console.log("Logged in");
},
);
}
Loading

0 comments on commit 15af2f4

Please sign in to comment.