-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
84 additions
and
0 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
32 changes: 32 additions & 0 deletions
32
packages/app-node/src/backend/authentication/http-routes/logout.ts
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,32 @@ | ||
import { parse } from "cookie" | ||
|
||
import { respondJson } from "@dassie/lib-http-server" | ||
import { createActor } from "@dassie/lib-reactive" | ||
|
||
import { SESSION_COOKIE_NAME } from "../../../common/constants/cookie-name" | ||
import { restApiService } from "../../http-server/serve-rest-api" | ||
import { sessionsStore } from "../database-stores/sessions" | ||
import { SessionToken } from "../types/session-token" | ||
|
||
export const registerLogoutRoute = () => | ||
createActor((sig) => { | ||
const api = sig.get(restApiService) | ||
const sessions = sig.use(sessionsStore) | ||
if (!api) return | ||
|
||
api.post("/api/logout").handler((request, response) => { | ||
const cookies = parse(request.headers.cookie ?? "") | ||
const currentSessionToken = cookies[SESSION_COOKIE_NAME] | ||
if (currentSessionToken) { | ||
sessions.removeSession(currentSessionToken as SessionToken) | ||
} | ||
response.cookie(SESSION_COOKIE_NAME, "", { | ||
httpOnly: true, | ||
secure: true, | ||
sameSite: "strict", | ||
expires: new Date(0), | ||
}) | ||
|
||
respondJson(response, 200, {}) | ||
}) | ||
}) |
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
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
20 changes: 20 additions & 0 deletions
20
packages/app-node/src/frontend/pages/settings/settings.tsx
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,20 @@ | ||
import { useMutation } from "@tanstack/react-query" | ||
|
||
import { Button } from "../../components/ui/button" | ||
import { logout } from "../../utils/authentication" | ||
import { queryClientReactContext } from "../../utils/trpc" | ||
|
||
export const Settings = () => { | ||
const logoutMutation = useMutation({ | ||
mutationFn: logout, | ||
onSuccess: () => { | ||
window.location.reload() | ||
}, | ||
context: queryClientReactContext, | ||
}) | ||
return ( | ||
<div> | ||
<Button onClick={() => logoutMutation.mutate()}>Logout</Button> | ||
</div> | ||
) | ||
} |
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
a69e725
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
dassieland – ./
dassieland.vercel.app
dassieland-git-main-justmoon.vercel.app
www.dassie.land
dassieland-justmoon.vercel.app
dassie.land