Add exchange api endpoint, fix jwt authtoken var type error

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2026-01-20 18:51:15 +08:00
parent 9b83ab565a
commit cd93491d98
8 changed files with 75 additions and 48 deletions

View File

@@ -31,43 +31,6 @@ func Redirect(c *gin.Context) {
}
code := c.Query("code")
if code == "" {
userIdOrig, ok := c.Get("user_id")
if !ok || userIdOrig == "" {
utils.HttpResponse(c, 401, "", "unauthorized")
return
}
userId, err := uuid.Parse(userIdOrig.(string))
if err != nil {
utils.HttpResponse(c, 500, "", "failed to parse uuid")
return
}
userData := new(data.User)
user, err := userData.GetByUserId(userId)
if err != nil {
utils.HttpResponse(c, 500, "", "failed to get user id")
return
}
code, err := authcode.NewAuthCode(clientId, user.Email)
if err != nil {
utils.HttpResponse(c, 500, "", "code gen failed")
return
}
url, err := url.Parse(redirectUri)
if err != nil {
utils.HttpResponse(c, 400, "", "invalid redirect uri")
return
}
query := url.Query()
query.Set("code", code)
url.RawQuery = query.Encode()
c.Redirect(302, url.String())
}
// Verify email token
authCode, ok := authcode.VerifyAuthCode(code)