forked from mirrors/pronouns.cc
fix(api): return correct struct in /auth/discord/callback
This commit is contained in:
parent
ecd049088a
commit
ad2c527e0e
2 changed files with 31 additions and 3 deletions
|
@ -33,7 +33,7 @@ type discordCallbackResponse struct {
|
|||
HasAccount bool `json:"has_account"` // if true, Token and User will be set. if false, Ticket and Discord will be set
|
||||
|
||||
Token string `json:"token,omitempty"`
|
||||
User *db.User `json:"user,omitempty"`
|
||||
User *userResponse `json:"user,omitempty"`
|
||||
|
||||
Discord string `json:"discord,omitempty"` // username, for UI purposes
|
||||
Ticket string `json:"ticket,omitempty"`
|
||||
|
@ -87,8 +87,9 @@ func (s *Server) discordCallback(w http.ResponseWriter, r *http.Request) error {
|
|||
render.JSON(w, r, discordCallbackResponse{
|
||||
HasAccount: true,
|
||||
Token: token,
|
||||
User: &u,
|
||||
User: dbUserToUserResponse(u),
|
||||
})
|
||||
|
||||
return nil
|
||||
|
||||
} else if err != db.ErrUserNotFound { // internal error
|
||||
|
|
|
@ -4,11 +4,13 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
|
||||
"codeberg.org/u1f320/pronouns.cc/backend/db"
|
||||
"codeberg.org/u1f320/pronouns.cc/backend/log"
|
||||
"codeberg.org/u1f320/pronouns.cc/backend/server"
|
||||
"emperror.dev/errors"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/render"
|
||||
"github.com/rs/xid"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
|
@ -17,6 +19,31 @@ type Server struct {
|
|||
RequireInvite bool
|
||||
}
|
||||
|
||||
type userResponse struct {
|
||||
ID xid.ID `json:"id"`
|
||||
Username string `json:"username"`
|
||||
DisplayName *string `json:"display_name"`
|
||||
Bio *string `json:"bio"`
|
||||
AvatarURL *string `json:"avatar_url"`
|
||||
Links []string `json:"links"`
|
||||
|
||||
Discord *string `json:"discord"`
|
||||
DiscordUsername *string `json:"discord_username"`
|
||||
}
|
||||
|
||||
func dbUserToUserResponse(u db.User) *userResponse {
|
||||
return &userResponse{
|
||||
ID: u.ID,
|
||||
Username: u.Username,
|
||||
DisplayName: u.DisplayName,
|
||||
Bio: u.Bio,
|
||||
AvatarURL: u.AvatarURL,
|
||||
Links: u.Links,
|
||||
Discord: u.Discord,
|
||||
DiscordUsername: u.DiscordUsername,
|
||||
}
|
||||
}
|
||||
|
||||
func Mount(srv *server.Server, r chi.Router) {
|
||||
s := &Server{
|
||||
Server: srv,
|
||||
|
|
Loading…
Reference in a new issue