Skip to content

Commit

Permalink
fix: login btn (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
subfuzion authored Mar 21, 2023
1 parent 50ae62b commit 95f422a
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/components/login-btn.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { signIn, signOut } from "next-auth/react"
import { useEffect } from "react";
import { useGetUserQuery } from "src/redux/apiSlice";
import { startMission } from "src/redux/gameSlice";
import { useAppDispatch } from "src/redux/hooks";
import {signIn, signOut} from "next-auth/react";
import {useEffect} from "react";
import {useGetUserQuery} from "src/redux/apiSlice";
import {startMission} from "src/redux/gameSlice";
import {useAppDispatch} from "src/redux/hooks";


export default function Component() {
const dispatch = useAppDispatch()
const dispatch = useAppDispatch();

const {
data: user,
Expand All @@ -16,29 +17,32 @@ export default function Component() {
} = useGetUserQuery();

useEffect(() => {
if(user) {
dispatch(startMission({ user }))
if (user) {
dispatch(startMission({user}));
}
}, [dispatch, user]);

if (isLoading) {
return <div>Loading...</div>
} else if (isSuccess) {
if (user.email) {
return (
return <div>Loading...</div>;
}

if (isError) {
return <div>{error.toString()}</div>;
}

if (isSuccess && user.email) {
return (
<>
Signed in as {JSON.stringify(user.email)} <br />
Signed in as {JSON.stringify(user.email)} <br/>
<button onClick={() => signOut()}>Sign out</button>
</>
)
}
return (
);
}

return (
<>
Not signed in <br />
Not signed in <br/>
<button onClick={() => signIn()}>Sign in</button>
</>
)
} else if (isError) {
return <div>{error.toString()}</div>
}
);
}

0 comments on commit 95f422a

Please sign in to comment.