Skip to content

fix: perform log out server action with state #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use server';

import { signOut } from '@/auth';
import { SignOutParams } from 'next-auth/react';

export async function signOutAction(params: SignOutParams) {
await signOut({ ...params });
}
1 change: 0 additions & 1 deletion src/app/(app)/[repo]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
export default async function Page({ params }: Props) {
const { repo: rawRepo } = await params;
const repo = decodeURIComponent(rawRepo);
console.log(repo);

// check if it has prefix '@'
// otherwise call notFount
Expand Down
20 changes: 18 additions & 2 deletions src/app/(app)/_components/header/user-dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';

import { signOutAction } from '@/actions';
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import {
DropdownMenu,
Expand All @@ -9,13 +10,17 @@ import {
DropdownMenuShortcut,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import { Spinner } from '@/components/ui/spinner';
import { ExternalLink, LogOutIcon } from 'lucide-react';
import { useSession } from 'next-auth/react';
import { useState } from 'react';

export default function UserDropdown() {
const { data: session } = useSession();
const { username, name, email, image } = session?.user ?? {};

const [isLoggingOut, setIsLoggingOut] = useState(false);

return (
<DropdownMenu>
<DropdownMenuTrigger>
Expand All @@ -40,10 +45,21 @@ export default function UserDropdown() {
</DropdownMenuShortcut>
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem className="cursor-pointer">
<DropdownMenuItem
className="cursor-pointer"
disabled={isLoggingOut}
onClick={async () => {
setIsLoggingOut(true);
await signOutAction({ redirectTo: '/login' });
}}
>
Log out
<DropdownMenuShortcut>
<LogOutIcon className="size-4" />
{isLoggingOut ? (
<Spinner className="bg-foreground size-4" />
) : (
<LogOutIcon className="size-4" />
)}
</DropdownMenuShortcut>
</DropdownMenuItem>
</DropdownMenuContent>
Expand Down
2 changes: 1 addition & 1 deletion src/app/(app)/new/_components/repo-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default function RepoList() {
const { data: session, status } = useSession();
const accessToken = session?.accessToken;
const username = session?.user?.username;
console.log(session?.user);

const [search, setSearch] = useState('');
const debouncedSearch = useDebounce(search, 500);

Expand Down