Skip to content

Commit

Permalink
로그인하기(2)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorious77 committed May 8, 2022
1 parent 14e7458 commit 0fcbe3f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { useState } from "react";
import { Auth } from "./Auth";
import Route from "./Route";

function App() {
const [user, setUser] = useState(null);

return (
<div className="App">
<Route />
<Route user={user} setUser={setUser} />
<Auth setUser={setUser} />
</div>
);
}
Expand Down
13 changes: 13 additions & 0 deletions src/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import {
GoogleAuthProvider,
signInWithPopup,
signOut as googleSignOut,
onAuthStateChanged,
} from "firebase/auth";
import { useEffect } from "react";
import { getAuthUsers } from "./Firebase";

const provider = new GoogleAuthProvider();
Expand Down Expand Up @@ -48,6 +50,17 @@ export const signOut = async (setUser) => {
console.log("signOut Success!");
})
.catch((e) => {
console.log(e);
console.log("signOut failed");
});
};

export const Auth = ({ setUser }) => {
useEffect(() => {
onAuthStateChanged(getAuth(), (user) => {
if (user) {
setUser(user);
}
});
}, [setUser]);
};

0 comments on commit 0fcbe3f

Please sign in to comment.