Skip to content

Removed React-Auth-kit #3

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

Merged
merged 7 commits into from
Mar 24, 2024
Merged

Removed React-Auth-kit #3

merged 7 commits into from
Mar 24, 2024

Conversation

Jgarnes
Copy link
Collaborator

@Jgarnes Jgarnes commented Mar 16, 2024

Removed React-Auth-kit because direction was changed to use Google Firebase instead

@Jgarnes Jgarnes self-assigned this Mar 16, 2024
Copy link
Owner

@chrisuribe chrisuribe left a comment

Choose a reason for hiding this comment

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

Solid work. Please make the following changes and then I'll be ready to merge it in. :)

}).catch(error => console.log(error))
}

return <div>{authUser ? <><p>{`Signed In as ${authUser}`}</p><button onClick={userSignOut}> Sign Out</button> </> : <p>Signed Out</p>}</div>
Copy link
Owner

Choose a reason for hiding this comment

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

Use an authUser property such as email.
Something like this:
{`Signed In as ${authUser.email}`}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've tried doing it as you suggested, however I got an error. so instead I used this ${auth.currentUser?.email}

Copy link
Owner

Choose a reason for hiding this comment

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

oops! Yes, you're correct.

@@ -0,0 +1,28 @@
import { onAuthStateChanged, signOut } from "firebase/auth";
Copy link
Owner

Choose a reason for hiding this comment

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

Import User from "firebase/auth" so that you can use it with your authUser hook.
Like this:
import { onAuthStateChanged, signOut, User } from 'firebase/auth';

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

import { auth } from '../../firebase-config';

const AuthDetails = () => {
const [authUser, setAuthUser] = useState(null);
Copy link
Owner

Choose a reason for hiding this comment

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

Make sure to specify the type User or null for your hooks.
Like this:
const [authUser, setAuthUser] = useState<User | null>(null);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done. I'm still getting familiar and functionality of hooks and useState

useEffect(() => {
const listen = onAuthStateChanged(auth, (user) => {
if (user) {
setAuthUser
Copy link
Owner

Choose a reason for hiding this comment

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

Looks like you forgot to use this hook and set the user once it comes in.
Update with:
setAuthUser(user);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done. I did do that at first. But it was throwing an error. I tried different variations to solve why but in the end i just removed it.

const [authUser, setAuthUser] = useState(null);

useEffect(() => {
const listen = onAuthStateChanged(auth, (user) => {
Copy link
Owner

@chrisuribe chrisuribe Mar 24, 2024

Choose a reason for hiding this comment

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

Recommend renaming 'listen' to 'removeAuthListener' since that more clearly communicates that this funciton will remove the listener that was setup when a subscription was created that runs a callback whenver the authentication state changes.
For example:
const removeAuthListener = onAuthStateChanged(auth, (user) => {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done. Is this more so just have better naming conventions as to make it more clean code for it to be understood by the next person?

setAuthUser(null);
}
})
return () => listen();
Copy link
Owner

Choose a reason for hiding this comment

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

Also, if listen is changed to removeAuthListener, make sure to update this line too. Like this:
return () => removeAuthListener();

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Copy link
Owner

@chrisuribe chrisuribe left a comment

Choose a reason for hiding this comment

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

You rock!

@chrisuribe chrisuribe merged commit a2435c8 into chrisuribe:main Mar 24, 2024
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