Skip to content

feat(auth): integrate LoginPage and RegisterPage with API client - #2

Merged
Zohaibarif69 merged 1 commit into
mainfrom
feature/auth-integration
May 28, 2026
Merged

feat(auth): integrate LoginPage and RegisterPage with API client#2
Zohaibarif69 merged 1 commit into
mainfrom
feature/auth-integration

Conversation

@Zohaibarif69

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings May 26, 2026 09:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the frontend auth flow to use the shared apiClient (calling real backend /auth/login and /auth/register) and refactors AppContext auth helpers to accept a user object instead of validating credentials client-side.

Changes:

  • Wire LoginPage and RegisterPage to apiClient.login() / apiClient.register() and log the user in on success.
  • Refactor AppContext.login to dispatch a user payload directly (and remove the old in-memory credential check/register helper).
  • Update the login demo credentials shown on the page.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
frontend/src/app/pages/RegisterPage.tsx Uses apiClient.register() then calls AppContext.login() with returned user fields; adds error handling.
frontend/src/app/pages/LoginPage.tsx Uses apiClient.login() then calls AppContext.login(); updates demo credentials display.
frontend/src/app/context/AppContext.tsx Changes login signature to accept a user object and removes the previous local credential-based login/register logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +41 to +47
const response = await apiClient.register(form.name.trim(), form.email, form.password);
login({
id: response.data.id,
name: response.data.name,
email: response.data.email,
role: response.data.role as "admin" | "member",
});
Comment on lines +50 to +54
} catch (error: any) {
toast.error(error.message || "Registration failed");
if (error.message.includes("email")) {
setErrors((p) => ({ ...p, email: error.message }));
}
Comment on lines +32 to +38
const response = await apiClient.login(email, password);
login({
id: response.data.id,
name: response.data.name,
email: response.data.email,
role: response.data.role as "admin" | "member",
});
Comment on lines +41 to +42
} catch (error: any) {
toast.error(error.message || "Invalid email or password");
Comment on lines +282 to +287
function login(user: Omit<User, "avatar" | "password">): void {
const loginUser: User = {
...user,
avatar: undefined,
};
dispatch({ type: "LOGIN", payload: loginUser });
@Zohaibarif69
Zohaibarif69 merged commit 863f9e2 into main May 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants