Skip to content

Commit da160cf

Browse files
committed
✨ log out of web interface
1 parent cc8ed96 commit da160cf

File tree

6 files changed

+44
-3
lines changed

6 files changed

+44
-3
lines changed

userland/web/routes/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Routes"""
22

3-
from . import chat
3+
from . import chat, logout
44

5-
__all__ = ("chat",)
5+
__all__ = ("chat", "logout")

userland/web/routes/logout.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Web chat"""
2+
3+
# stdlib
4+
from typing import Annotated
5+
6+
# 3rd party
7+
from fastapi import Depends, HTTPException
8+
9+
# api
10+
from xthulu.models.user import User
11+
from xthulu.web.auth import login_user
12+
13+
# local
14+
from .. import api
15+
16+
17+
@api.get("/logout/")
18+
def chat(user: Annotated[User, Depends(login_user)]):
19+
"""End the user session."""
20+
21+
raise HTTPException(status_code=401)

userland/web/static/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ <h1>xthulu</h1>
1010
<h2>Pages</h2>
1111
<ul>
1212
<li>
13-
<a href="chat/">Chat</a>
13+
<a href="/chat/">Chat</a>
14+
</li>
15+
<li>
16+
<a href="/logout/">Logout</a>
1417
</li>
1518
</ul>
1619
</body>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>xthulu logout</title>
6+
<meta name="viewport" content="width=device-width,initial-scale=1" />
7+
</head>
8+
<body>
9+
<p>Cancel any login prompt in order to clear your credentials.</p>
10+
<p>
11+
<a href="/">Home</a>
12+
</p>
13+
<script type="module" src="script.ts"></script>
14+
</body>
15+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
await fetch("/api/logout/").then(() => window.location.assign("/"));

userland/web/static/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default defineConfig({
99
input: {
1010
chat: resolve(__dirname, "chat/index.html"),
1111
index: resolve(__dirname, "index.html"),
12+
logout: resolve(__dirname, "logout/index.html"),
1213
},
1314
},
1415
target: "esnext",

0 commit comments

Comments
 (0)