mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-06-28 16:20:34 +08:00
Using more pydantic features in the backend and fixing env issues on the website
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import json
|
||||
from typing import Union
|
||||
|
||||
from cryptography.hazmat.primitives import hashes
|
||||
@@ -7,7 +6,7 @@ from fastapi import APIRouter, Depends, Security
|
||||
from fastapi.security import APIKeyCookie
|
||||
from jose import jwe
|
||||
from oasst_backend.config import settings
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, EmailStr
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -19,7 +18,7 @@ class TokenData(BaseModel):
|
||||
A minimal re-creation of the web's token type. To be expanded later.
|
||||
"""
|
||||
|
||||
email: Union[str, None] = None
|
||||
email: Union[EmailStr, None] = None
|
||||
|
||||
|
||||
async def get_current_user(token: str = Security(oauth2_scheme)):
|
||||
@@ -38,9 +37,7 @@ async def get_current_user(token: str = Security(oauth2_scheme)):
|
||||
# Next we decrypt the JWE token.
|
||||
payload = jwe.decrypt(token, key)
|
||||
# Finally we have the real token JSON payload and can do whatever we want.
|
||||
content = json.loads(payload)
|
||||
email = content["email"]
|
||||
return TokenData(email=email)
|
||||
return TokenData.parse_raw(payload)
|
||||
|
||||
|
||||
@router.get("/check", response_model=str)
|
||||
|
||||
@@ -7,6 +7,7 @@ loguru==0.6.0
|
||||
numpy==1.22.4
|
||||
psycopg2-binary==2.9.5
|
||||
pydantic==1.9.1
|
||||
pydantic[email]==1.9.1
|
||||
python-dotenv==0.21.0
|
||||
python-jose[cryptography]==3.3.0
|
||||
redis
|
||||
|
||||
@@ -7,6 +7,9 @@ DATABASE_URL=postgres://postgres:postgres@localhost:5433/oasst_web
|
||||
FASTAPI_URL=http://localhost:8080
|
||||
FASTAPI_KEY=1234
|
||||
|
||||
# Used to expose the backend url to the clientside javascript
|
||||
NEXT_PUBLIC_BACKEND_URL=$FASTAPI_URL
|
||||
|
||||
# A dev Auth Secret. Can be exposed if we never use this publicly.
|
||||
NEXTAUTH_SECRET=O/M2uIbGj+lDD2oyNa8ax4jEOJqCPJzO53UbWShmq98=
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import useSWR from "swr";
|
||||
|
||||
const Dashboard = () => {
|
||||
// Adding a demonstrative call to the backend that includes the web's JWT.
|
||||
useSWR(`${process.env.FASTAPI_URL}/api/v1/auth/check`, get);
|
||||
useSWR(`${process.env.NEXT_PUBLIC_BACKEND_URL}/api/v1/auth/check`, get);
|
||||
|
||||
const {
|
||||
t,
|
||||
|
||||
Reference in New Issue
Block a user