我真的是个新手。我试图从我的vue3服务器到FastApi服务器,得到了422。据我所知,这种错误消息与错误输入有关。
这是vue3代码
import { authToken } from "../main.js"
export default {
...
mounted() {
const response = axios.get('/checkIsLogged', authToken);
console.log("authToken" + authToken)
this.isLoggedIn = response
console.log("isLoggedin", response)
if (response) {
this.title3 = "Mi perfil"
} else {
this.title1 = "Sign in"
}
},
其中“authToken”
export const authToken = ""
export const setAuthToken = (token) => {
authToken = token
}
另一方面,在FastApi中,方法是->
@empresa.get("/checkIsLogged", response_model=bool)
def is_token_expired(authToken: str):
try:
payload = jwt.decode(authToken, SECRET_KEY, algorithms=[ALGORITHM])
expiration_timestamp = payload.get("exp")
if expiration_timestamp is None:
return True
expiration_datetime = datetime.fromtimestamp(expiration_timestamp)
current_datetime = datetime.now()
if current_datetime >= expiration_datetime:
return True
return False
except JWTError:
return False
我做错了什么?
提前感谢。