Skip to content

Commit c56584a

Browse files
kstrassheimKonstantin Strassheim
andauthored
Logon frame (+ new logo
* added logon functionality * added logo --------- Co-authored-by: Konstantin Strassheim <[email protected]>
1 parent 9c4c917 commit c56584a

File tree

18 files changed

+988
-56
lines changed

18 files changed

+988
-56
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ The app which fulfills the following requirements for a
88
- Deployment of a productive version with precompiled frontend server
99
- Deployment to Azure App Service Free Plan with Actions on Pull Request
1010
- Handle Front and Backend routing in FastAPI both together
11+
- Handle 404 page
12+
- A frame for further development with server side Authentication
1113

1214
## Prerequisites
1315
Here are the prerequisites that you have to install before running the app

backend/api.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from fastapi import APIRouter
2+
3+
api_router = APIRouter()
4+
@api_router.get("/data")
5+
def read_hello():
6+
return {"message": "Hello from API"}

backend/auth.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from fastapi import APIRouter
2+
from fastapi.encoders import jsonable_encoder
3+
from pydantic import BaseModel
4+
5+
class LoginItem(BaseModel):
6+
message: str
7+
8+
auth_router = APIRouter()
9+
@auth_router.post("/login")
10+
async def login(loginitem: LoginItem):
11+
data = jsonable_encoder(loginitem)
12+
return {"token": "ABCDEF", "data": data}
13+
14+
@auth_router.post("/logout")
15+
async def login():
16+
return {"message": 'Loggout ok'}

backend/main.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
from fastapi.staticfiles import StaticFiles
44
from fastapi.responses import FileResponse, RedirectResponse
55
from pathlib import Path
6+
from auth import auth_router
7+
from api import api_router
68
# Init FastAPI
79
app = FastAPI()
810
origins = ["http://localhost:5173", "localhost:5173"]
911
app.add_middleware(CORSMiddleware,allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"])
1012

11-
# API Router
12-
api_router = APIRouter()
13-
@api_router.get("/hello")
14-
def read_hello():
15-
return {"message": "Hello from API"}
13+
# Register Auth Router
14+
app.include_router(auth_router, prefix="/auth")
15+
16+
# Register API Router
1617
app.include_router(api_router, prefix="/api")
1718

1819
# Frontend Router

frontend/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
5-
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
5+
<link rel="icon" type="image/svg+xml" href="/logo.svg" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>EntraID-Web-Auth-Reference</title>
7+
<title>FastAPI-Reference</title>
88
</head>
99
<body>
1010
<div id="root"></div>

frontend/public/favicon.ico

14.7 KB
Binary file not shown.

frontend/public/logo.svg

Lines changed: 775 additions & 0 deletions
Loading

frontend/public/vite.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

frontend/src/404.jsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Link } from "react-router-dom";
2+
export default function NotFound() {
3+
return (
4+
<>
5+
<h1>404</h1>
6+
<Link to='/'>Goto Home</Link>
7+
</>
8+
);
9+
}
10+

frontend/src/App.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import { useState, useEffect } from 'react'
22
import { Routes, Route } from "react-router-dom";
3-
import Login from './components/Login';
3+
import { RequireToken, setToken } from "./components/auth";
4+
import Login from './Login';
45
import Home from './pages/Home';
6+
import NotFound from './404';
57
import './App.css'
68

79
function App() {
810
return (
911
<>
1012
<div className ="App">
1113
<Routes>
12-
<Route path="/" element = {<Home/>}/>
14+
<Route path="/" element = {<RequireToken><Home/></RequireToken>}/>
1315
<Route path="/login" element = {<Login/>}/>
16+
<Route path="*" element = {<NotFound/>}/>
1417
</Routes>
1518
</div>
1619
</>

0 commit comments

Comments
 (0)