Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login and Signup Page #1 (Fiona) #3

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Conversation

fionapeng16
Copy link

@fionapeng16 fionapeng16 commented Nov 22, 2024

Created Login and Signup pages:

  1. Login Page (/login)
  • created Next.js Form with the following fields: Student Email, Student ID, Password
  • added a "Sign Up" button that redirects users to the /signup page
  • temporarily logs the form data in JSON format to the server console for verification
  1. SignUp Page (/signup)
  • created Next.js Form with the following fields: Student Email, Student ID, Password, Confirm Password
  • verifies passwords match
  • added a "Log In" button that redirects users to the /login page
  • temporarily logs the form data in JSON format to the server console for verification
    LoginPage and SignUpPage components

UPDATE:

  1. /login (/login/eo-admin, /login/school-admin, /login/students)
  2. /signup (/signup/eo-admin, /signup/school-admin, /signup/students)
  • created signUp.ts, signIn.ts, and logout.ts files using the Firebase documentation (under /firebase/auth)
  • called these functions in the UI (signUp and signIn)
  • created separate login and signup pages for school-admin, eo-admin, and students (/login and /signup each have a menu that allows user to select who they want to signup/login as)
  • differentiated between the roles so when the user signs in, it checks if their role when they signed up (determined by which signup page they used) matches the signin page role (it querys the firestore to find the user)
  • still need to have the eo-admin approve school-admin and still need to implement logout

@fionapeng16 fionapeng16 self-assigned this Nov 22, 2024
Comment on lines 4 to 9
// interface metadata {
// title: string;
// }
export const metadata = {
title: 'Log In',
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

make sure to remove any unused code for the PR (this can be done in this PR or if you can follow up with this in the next PR that would be great!)

@coshio
Copy link
Collaborator

coshio commented Nov 26, 2024

We reverted back to Next 14 which means that the old Form component that was used isn't compatible. This was changed in the latest commit

@@ -0,0 +1,13 @@
import firebase_app from '@/firebase/config';
Copy link
Collaborator

Choose a reason for hiding this comment

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

make this function be executed on the server by including the "use server" directive at the very top!

@@ -0,0 +1,20 @@
import firebase_app from '@/firebase/config';
Copy link
Collaborator

Choose a reason for hiding this comment

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

"use server" here too

@@ -0,0 +1,24 @@
import firebase_app from '@/firebase/config';
Copy link
Collaborator

Choose a reason for hiding this comment

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

"use server"

export default async function signUp(
email: string,
password: string
): Promise<{ result: UserCredential | null; error: Error | null }> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

you'll probably encounter this error after adding "use server" because you'll now be calling a server action when you call "signUp" in the signup pages, which are client components -- basically there are certain restrictions in place when you pass data between server and client components "Error: Only plain objects, and a few built-ins, can be passed to Client Components from Server Components. Classes or null prototypes are not supported."

so instead of returning the UserCredential object, return a serialized version of the result.

export default async function signUp(
email: string,
password: string
): Promise<{ result: UserCredential | null; error: Error | null }> {
Copy link
Collaborator

@joycechen721 joycechen721 Dec 6, 2024

Choose a reason for hiding this comment

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

Promise<{
result: SignUpResult | null;
error: string | null;
}>

type SignUpResult = { userId: string; email: string | null };

email,
password
);
return { result, error: null };
Copy link
Collaborator

Choose a reason for hiding this comment

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

return {
result: serializedResult,
error: null,
};

);
return { result, error: null };
} catch (error) {
return { result: null, error: error as Error };
Copy link
Collaborator

Choose a reason for hiding this comment

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

return { result: null, error: (error as Error).message };

Copy link
Collaborator

@joycechen721 joycechen721 left a comment

Choose a reason for hiding this comment

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

thanks fiona!! just a few refactoring to do with the functions but otherwise looks amazing <3

setError(error.message);
} else {
try {
const db = getFirestore();
Copy link
Collaborator

Choose a reason for hiding this comment

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

we'll probably have extract this firebase update into a server component or route handler in the future :D but dw about it for now!!

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.

4 participants