Skip to content

Commit

Permalink
updating signout button to redirect to home page on success & toast e…
Browse files Browse the repository at this point in the history
…rror to retry on error
  • Loading branch information
bbland1 committed Aug 26, 2024
1 parent 633bf67 commit 70791d2
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/api/useAuth.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
import { auth } from "./config.js";
import { GoogleAuthProvider, signInWithPopup } from "firebase/auth";
import { addUserToDatabase, User } from "./firebase";
import toast from "react-hot-toast";

/**
* A button that signs the user in using Google OAuth. When clicked,
Expand All @@ -20,11 +22,30 @@ export const SignInButton = () => (
/**
* A button that signs the user out of the app using Firebase Auth.
*/
export const SignOutButton = () => (
<button type="button" onClick={() => auth.signOut()}>
Sign Out
</button>
);
export const SignOutButton = () => {
const navigate = useNavigate();

return (
<button
type="button"
onClick={() => {
auth
.signOut()
.then(() => {
navigate("/");
})
.catch((error) => {
console.error(error);
toast.error(
"An error occurred while signing out. Please try again.",
);
});
}}
>
Sign Out
</button>
);
};

/**
* A custom hook that listens for changes to the user's auth state.
Expand Down

0 comments on commit 70791d2

Please sign in to comment.