Skip to content

Commit

Permalink
Use server action to login/logout (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yasamato authored Dec 8, 2024
1 parent 8c072d3 commit 82954b5
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions components/buttons/LoginOrOutButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,33 @@ const LoginOrOutButton: FC = () => {
const { data: session } = useSession()

return (
<button
role={'button'}
className={
'btn w-100 btn-outline-' + (isLogin(session) ? 'danger' : 'success')
}
onClick={async () => {
<form
action={async () => {
'use server'
if (isLogin(session)) {
await signOut()
} else {
await signIn('discord')
}
}}
>
{isLogin(session) ? (
<>
Sign out <FontAwesomeIcon icon={faSignOutAlt} />
</>
) : (
<>
<FontAwesomeIcon icon={faSignInAlt} /> Sign In
</>
)}
</button>
<button
type='submit'
className={
'btn w-100 btn-outline-' + (isLogin(session) ? 'danger' : 'success')
}
>
{isLogin(session) ? (
<>
Sign out <FontAwesomeIcon icon={faSignOutAlt} />
</>
) : (
<>
<FontAwesomeIcon icon={faSignInAlt} /> Sign In
</>
)}
</button>
</form>
)
}

Expand Down

0 comments on commit 82954b5

Please sign in to comment.