Skip to content

Commit

Permalink
Merge pull request #218 from osu-tournament-rating/feature/sign-out
Browse files Browse the repository at this point in the history
  • Loading branch information
hburn7 authored Aug 29, 2024
2 parents 56179b1 + 2f17c4b commit ba2d079
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
16 changes: 16 additions & 0 deletions app/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ export async function login(cookie: {
return NextResponse.redirect(new URL('/', process.env.REACT_APP_ORIGIN_URL));
}

export async function logout() {
const session = await getSession();

if (session) {
try {
session.destroy(); // delete the session made with IronSession - delete it's session cookie
await cookies().delete('OTR-Refresh-Token'); // delete the cookie that contains the refresh token
await cookies().delete('OTR-user-selected-osu-mode'); // delete the cookie that contains the selected osu mode
} catch (error) {
console.log(error);
} finally {
return redirect(new URL('/', process.env.REACT_APP_ORIGIN_URL));
}
}
}

export async function getLoggedUser(accessToken: string) {
let res = await fetch(`${process.env.REACT_APP_API_URL}/me`, {
method: 'GET',
Expand Down
3 changes: 3 additions & 0 deletions components/NavBar/NavBar.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
border: 0;
background: transparent;
cursor: pointer;
font-size: inherit;
font-weight: inherit;
color: inherit;
}

.iconContainer {
Expand Down
7 changes: 2 additions & 5 deletions components/NavBar/Tooltip/Tooltip.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,16 @@
transition: all 0.2s ease-out;
}

.tooltipContent > div {
.tooltipContent > :is(div, button) {
display: flex;
align-items: center;
justify-content: center;
}

.tooltipContent > div {
cursor: pointer;
transition: color 0.2s ease;
border-radius: 4px;
color: hsla(var(--foreground-inactive-hsl));
}

.tooltipContent > div:hover {
.tooltipContent > :is(div, button):hover {
color: hsla(var(--foreground-active-hsl));
}
8 changes: 7 additions & 1 deletion components/NavBar/UserLogged/UserLogged.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
'use client';

import { logout } from '@/app/actions';
import { useUser } from '@/util/hooks';
import Image from 'next/image';
import styles from '../NavBar.module.css';
import ThemeSwitcher from '../ThemeSwitcher/ThemeSwitcher';
import Tooltip from './../Tooltip/Tooltip';

const tooltipContent = (
<>
{/* <div>Friends</div> */}
<div>Sign out</div>
<div>
<form action={logout}>
<button>Sign out</button>
</form>
</div>
<div className={styles.iconContainer}>
<ThemeSwitcher />
</div>
Expand Down

0 comments on commit ba2d079

Please sign in to comment.