Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added additional checks while retrieving user id from auth0 #148

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions backend/src/helper/auth0.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -76,11 +77,24 @@ func getAuth0UserIdByEmail(user *models.UserModel, token *ManagementApiToken) er
return err
}

if resp.StatusCode != http.StatusOK {
defer resp.Body.Close()
bytes, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
return fmt.Errorf("response code %d encountered while retrieving user id: %s", resp.StatusCode, string(bytes))
}

var userId []*Auth0UserId
err = json.NewDecoder(resp.Body).Decode(&userId)
if err != nil {
return err
}
if len(userId) <= 0 {
return fmt.Errorf("user with %s has not been created", user.Email)
}

user.UserId = userId[0].UserId
return nil
}
Expand Down
Loading