Skip to content

Commit

Permalink
Remove unnecessary logout Client Component
Browse files Browse the repository at this point in the history
Since Next.js 13.4.6, calling `cookies().set()` in a Server Action invalidates
the client cache:

- vercel/next.js#42991 (comment)
- PR vercel/next.js#51290

This means that we no longer need the Client Component, because we do not need
to call router.refresh() anymore.
  • Loading branch information
karlhorky committed Jul 1, 2023
1 parent be1c7ca commit 529a55a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 38 deletions.
12 changes: 0 additions & 12 deletions app/LogoutButton.module.scss

This file was deleted.

22 changes: 0 additions & 22 deletions app/LogoutButton.tsx

This file was deleted.

13 changes: 13 additions & 0 deletions app/layout.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,16 @@
background-color: transparent;
}
}

.logoutButton {
border: 1px solid;
cursor: pointer;
background-color: white;
color: rgb(0, 31, 57);
border-radius: 5px;

&:hover {
background-color: rgb(0, 31, 57);
color: white;
}
}
12 changes: 8 additions & 4 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { cookies } from 'next/headers';
import Link from 'next/link';
import { ReactNode } from 'react';
import { getUserBySessionToken } from '../database/users';
import { logout } from './(auth)/logout/actions';
import { CookieBanner } from './CookieBanner';
import style from './layout.module.scss';
import { LogoutButton } from './LogoutButton';
import styles from './layout.module.scss';

export const robotoMono = Roboto_Mono({
subsets: ['latin'],
Expand Down Expand Up @@ -35,7 +35,7 @@ export default async function RootLayout({ children }: Props) {
<html lang="en" className={robotoMono.className}>
<body style={{ backgroundColor: 'rgb(0, 31, 57)' }}>
<CookieBanner />
<nav className={style.navigator}>
<nav className={styles.navigator}>
<div>
<Link href="/">home</Link> <Link href="/animals">animals</Link>{' '}
<Link href="/fruits">fruits</Link>
Expand All @@ -47,7 +47,11 @@ export default async function RootLayout({ children }: Props) {
{user ? (
<>
<div>{user.username}</div>
<LogoutButton />
<form>
<button className={styles.logoutButton} formAction={logout}>
logout
</button>
</form>
</>
) : (
<>
Expand Down

0 comments on commit 529a55a

Please sign in to comment.