fix: update authentication response handling in FastAPI and Next.js to reflect account setup status
This commit is contained in:
parent
d07f8f05f6
commit
7552be0bf2
2 changed files with 23 additions and 10 deletions
|
|
@ -49,16 +49,14 @@ async def setup_credentials(body: AuthCredentialsRequest, request: Request):
|
|||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
|
||||
token = create_session_token(body.username.strip())
|
||||
response = JSONResponse(
|
||||
username = body.username.strip()
|
||||
return JSONResponse(
|
||||
{
|
||||
"configured": True,
|
||||
"authenticated": True,
|
||||
"username": body.username.strip(),
|
||||
"authenticated": False,
|
||||
"username": username,
|
||||
}
|
||||
)
|
||||
set_session_cookie(response, token, request)
|
||||
return response
|
||||
|
||||
|
||||
@API_V1_AUTH_ROUTER.post("/login")
|
||||
|
|
|
|||
|
|
@ -126,10 +126,25 @@ export default function AuthGate() {
|
|||
return;
|
||||
}
|
||||
|
||||
if (isSetupMode) {
|
||||
setStatus({
|
||||
configured: true,
|
||||
authenticated: false,
|
||||
username: (payload as AuthStatus).username ?? cleanedUsername,
|
||||
});
|
||||
setPassword("");
|
||||
setConfirmPassword("");
|
||||
toast.success("Account created", {
|
||||
description: "Sign in with your new username and password to continue.",
|
||||
duration: 6000,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
setStatus({
|
||||
configured: Boolean(payload.configured),
|
||||
authenticated: Boolean(payload.authenticated),
|
||||
username: payload.username ?? cleanedUsername,
|
||||
configured: Boolean((payload as AuthStatus).configured),
|
||||
authenticated: Boolean((payload as AuthStatus).authenticated),
|
||||
username: (payload as AuthStatus).username ?? cleanedUsername,
|
||||
});
|
||||
setPassword("");
|
||||
setConfirmPassword("");
|
||||
|
|
@ -289,7 +304,7 @@ export default function AuthGate() {
|
|||
? "Saving credentials…"
|
||||
: "Signing in…"
|
||||
: isSetupMode
|
||||
? "Create login and continue"
|
||||
? "Create account"
|
||||
: "Sign in"}
|
||||
</button>
|
||||
</form>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue