Fixed qor admin companies users

This commit is contained in:
Nedim
2023-11-13 18:03:16 +01:00
parent 8f365557a8
commit 515134dde5
5 changed files with 18 additions and 11 deletions

View File

@@ -130,7 +130,12 @@ func Login(c *gin.Context) {
if usr.CheckPassword(user.Password, req.Password) {
if user.IsActive && user.LoginAttempts < 10 {
// Proceed with creating JWT token and resetting login attempts
token, err := usr.CreateSessionToken(user.ID, user.CompanyID)
if len(user.Companies) == 0 {
c.JSON(http.StatusInternalServerError, gin.H{"error": "User is not connected to a company"})
return
}
token, err := usr.CreateSessionToken(user.ID, user.Companies[0].ID)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Could not create JWT token"})
return