Fixed issues after first dev test

This commit is contained in:
belviskhoremk
2026-05-20 23:59:58 +00:00
parent e6340837f1
commit cccb6ded1d

View File

@@ -17,8 +17,14 @@ def _admin_client() -> Client:
async def register(req: RegisterRequest, db: asyncpg.Connection) -> dict: async def register(req: RegisterRequest, db: asyncpg.Connection) -> dict:
# Use admin API to create user with email_confirm=True so no confirmation
# email is sent and the client can log in immediately after registration.
try: try:
result = _client().auth.sign_up({"email": req.email, "password": req.password}) result = _admin_client().auth.admin.create_user({
"email": req.email,
"password": req.password,
"email_confirm": True,
})
except Exception as e: except Exception as e:
raise AppError("REGISTRATION_FAILED", str(e), 400) raise AppError("REGISTRATION_FAILED", str(e), 400)
@@ -35,15 +41,18 @@ async def register(req: RegisterRequest, db: asyncpg.Connection) -> dict:
user_id, req.email, req.resolved_name(), req.phone, user_id, req.email, req.resolved_name(), req.phone,
) )
if result.session: # Sign in immediately to return tokens
return { try:
"access_token": result.session.access_token, login_result = _client().auth.sign_in_with_password({"email": req.email, "password": req.password})
"refresh_token": result.session.refresh_token, except Exception as e:
"token_type": "bearer", raise AppError("REGISTRATION_FAILED", str(e), 400)
"expires_in": result.session.expires_in,
}
return {"message": "Account created successfully."} return {
"access_token": login_result.session.access_token,
"refresh_token": login_result.session.refresh_token,
"token_type": "bearer",
"expires_in": login_result.session.expires_in,
}
async def login(req: LoginRequest) -> dict: async def login(req: LoginRequest) -> dict: