FastAPI - Authentication and Security
What is wrong with this FastAPI role check code?
async def role_check(user: User = Depends(get_current_user)):
if 'admin' not in user.roles:
raise HTTPException(status_code=403)
return true
@app.get('/admin')
async def admin_route(allowed=Depends(role_check)):
if not allowed:
return {'error': 'Access denied'}
return {'msg': 'Welcome admin'}