-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feature: logout * nothing important * dry code and lint --------- Co-authored-by: Ebenezer Arthur <[email protected]>
- Loading branch information
Showing
5 changed files
with
171 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Form } from "@remix-run/react"; | ||
import { Button } from "./button"; | ||
import { Modal } from "./modal"; | ||
|
||
interface LogoutModalProps { | ||
isOpen: boolean; | ||
onCancel: () => void; | ||
onConfirm: () => void; | ||
} | ||
|
||
function LogoutModal({ isOpen, onCancel, onConfirm }: LogoutModalProps) { | ||
return ( | ||
<Modal open={isOpen} onClose={onCancel}> | ||
<div className="p-4"> | ||
<h2 className="text-base font-semibold flex items-center gap-1"> | ||
Logout | ||
</h2> | ||
<p className="mt-2">Are you sure you want to log out?</p> | ||
<div className="flex justify-end mt-4 gap-2"> | ||
<Button | ||
className="!text-black px-2 py-1 text-sm bg-gray-200 dark:bg-neutral-800 text-gray-800 !dark:text-white" | ||
onClick={onCancel} | ||
> | ||
Cancel | ||
</Button> | ||
<Form | ||
action="logout" | ||
method="post" | ||
className="transition-[background] duration-200 group cursor-pointer" | ||
> | ||
<Button | ||
onClick={onConfirm} | ||
className="text-white text-sm !bg-red-500" | ||
> | ||
Continue | ||
</Button> | ||
</Form> | ||
</div> | ||
</div> | ||
</Modal> | ||
); | ||
} | ||
|
||
export { LogoutModal }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { json } from "@remix-run/node"; | ||
import { authCookie } from "./cookies.server"; | ||
|
||
async function logout(request: Request) { | ||
return json(null, { | ||
status: 200, | ||
headers: { | ||
"Set-Cookie": await authCookie.serialize("auth", { | ||
maxAge: 0, | ||
}), | ||
}, | ||
}); | ||
} | ||
|
||
export { logout }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { redirect, type ActionFunctionArgs } from "@remix-run/node"; | ||
import { logout } from "~/lib/logout.server"; | ||
|
||
export async function action({ request }: ActionFunctionArgs) { | ||
return await logout(request); | ||
} | ||
|
||
export async function loader() { | ||
return redirect("/discussions"); | ||
} |