Skip to content

Commit

Permalink
Merge pull request #23 from fga-eps-mds/fix-login-social
Browse files Browse the repository at this point in the history
fix logical login social
  • Loading branch information
castroricardo1 authored Dec 11, 2023
2 parents 1cac684 + 048d07a commit eab13c7
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/controller/authController.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,22 @@ async def login_social(user: authSchema.UserSocial, db: Session = Depends(get_db

if existing_user is None:
new_user = userRepository.create_user_social(db, user.name, user.email)
access_token = security.create_access_token(data={"id": new_user.id, "email": new_user.email, "role": new_user.role})

return JSONResponse(status_code=200, content={ "access_token": access_token, "token_type": "bearer", "is_new_user": True, "user_id": new_user.id })
user_id = new_user.id
is_new_user = True
else:
access_token = security.create_access_token(data={"id": existing_user.id, "email": existing_user.email, "role": existing_user.role})
refresh_token = security.create_refresh_token(data={ "id": existing_user.id })

return JSONResponse(status_code=200, content={ "access_token": access_token, "refresh_token": refresh_token, "token_type": "bearer", "is_new_user": False })
user_id = existing_user.id
is_new_user = False

access_token = security.create_access_token(data={"id": user_id, "email": user.email, "role": "user"})
refresh_token = security.create_refresh_token(data={"id": user_id})

return JSONResponse(status_code=200, content={
"access_token": access_token,
"refresh_token": refresh_token,
"token_type": "bearer",
"is_new_user": is_new_user,
"user_id": user_id
})

# trata da renovação de tokens de acesso
@auth.post("/refresh", response_model=authSchema.RefreshTokenResponse)
Expand Down

0 comments on commit eab13c7

Please sign in to comment.