-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Conversation
src/app/login/page.tsx
Outdated
// interface metadata { | ||
// title: string; | ||
// } | ||
export const metadata = { | ||
title: 'Log In', | ||
}; |
There was a problem hiding this comment.
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!)
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 |
…nd-overdose into login-and-signup-1
…'t do signin auth yet - will do soon
… if the role doesn't match your own
…to login-and-signup-1
@@ -0,0 +1,13 @@ | |||
import firebase_app from '@/firebase/config'; |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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 }> { |
There was a problem hiding this comment.
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 }> { |
There was a problem hiding this comment.
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 }; |
There was a problem hiding this comment.
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 }; |
There was a problem hiding this comment.
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 };
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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!!
Created Login and Signup pages:
LoginPage and SignUpPage components
UPDATE: