Skip to content

Commit

Permalink
fix: oauth checks for both user types
Browse files Browse the repository at this point in the history
  • Loading branch information
harshkhandeparkar committed Dec 16, 2023
1 parent 0e77a0d commit a85baa6
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions controllers/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,26 @@ func OAuth(w http.ResponseWriter, r *http.Request) {
var isNewUser bool = false

college := ""
if reqFields.Type == OAUTH_TYPE_STUDENT {
student := models.Student{}
db.
Table("students").
Where("username = ?", userInfo.Username).
First(&student)
student := models.Student{}
db.
Table("students").
Where("username = ?", userInfo.Username).
First(&student)

isNewUser = student.Username != userInfo.Username
isNewUser = isNewUser || (student.Username != userInfo.Username)

userInfo.Email = student.Email
college = student.College
userInfo.Email = student.Email
college = student.College

} else if reqFields.Type == OAUTH_TYPE_MENTOR {
mentor := models.Mentor{}
db.
Table("mentors").
Where("username = ?", userInfo.Username).
First(&mentor)
mentor := models.Mentor{}
db.
Table("mentors").
Where("username = ?", userInfo.Username).
First(&mentor)

isNewUser = mentor.Username != userInfo.Username
isNewUser = isNewUser || (mentor.Username != userInfo.Username)

userInfo.Email = mentor.Email
}
userInfo.Email = mentor.Email

// Generate a JWT string for the user
jwtString, err := utils.GenerateLoginJwtString(utils.LoginJwtFields{
Expand Down

0 comments on commit a85baa6

Please sign in to comment.