diff --git a/app.py b/app.py index 94b2a63a..959e1273 100644 --- a/app.py +++ b/app.py @@ -1,6 +1,9 @@ +from urllib.request import Request from fastapi import FastAPI from src.main import global_router from fastapi.middleware.cors import CORSMiddleware +from fastapi.responses import JSONResponse +from fastapi_jwt_auth.exceptions import AuthJWTException ######################## # Pre-Alpha Version 0.1.0 @@ -8,7 +11,8 @@ from fastapi.middleware.cors import CORSMiddleware # (c) LearnHouse 2022 ######################## -# Init +# +# Global Config app = FastAPI( title="LearnHouse", description="LearnHouse is a new open-source platform tailored for learning experiences.", @@ -24,8 +28,16 @@ app.add_middleware( allow_headers=["*"] ) -app.include_router(global_router) +# +# Exception Handler +@app.exception_handler(AuthJWTException) +def authjwt_exception_handler(request: Request, exc: AuthJWTException): + return JSONResponse( + status_code=exc.status_code, + content={"detail": exc.message} + ) +app.include_router(global_router) @app.get("/") async def root(): diff --git a/front/components/auth/HeaderProfileBox.tsx b/front/components/auth/HeaderProfileBox.tsx index d75bb8db..5e3e596a 100644 --- a/front/components/auth/HeaderProfileBox.tsx +++ b/front/components/auth/HeaderProfileBox.tsx @@ -1,12 +1,15 @@ import React from "react"; import styled from "styled-components"; import Link from "next/link"; +import { AuthContext } from "../security/AuthProvider"; export const HeaderProfileBox = () => { + const auth: any = React.useContext(AuthContext); + return ( {" "} - HeaderProfileBox{" "} + HeaderProfileBox {String(auth.isAuthenticated)}{" "}