Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,9 @@ func NewApiServer(config config.Config) *ApiServer {
g.Post("/oauth/token", app.v1OAuthToken)
g.Post("/oauth/revoke", app.v1OAuthRevoke)
g.Get("/me", app.requireAuthMiddleware, app.v1Me)
// Legacy alias for @audius/sdk <= 14, which calls /v1/oauth/me and
// expects the DecodedUserToken shape (userId, name, handle, ...).
g.Get("/oauth/me", app.requireAuthMiddleware, app.v1OAuthMe)

// Rewards
g.Post("/rewards/claim", app.v1ClaimRewards)
Expand Down
44 changes: 44 additions & 0 deletions api/v1_me.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package api

import (
"time"

"api.audius.co/api/dbv1"
"github.com/gofiber/fiber/v2"
"go.uber.org/zap"
Expand Down Expand Up @@ -34,3 +36,45 @@ func (app *ApiServer) v1Me(c *fiber.Ctx) error {

return c.JSON(fiber.Map{"data": users[0]})
}

// v1OAuthMe handles GET /v1/oauth/me
// Legacy endpoint that returns the user profile in the DecodedUserToken shape
// expected by @audius/sdk versions <= 14. Newer SDKs use /v1/me which returns
// the standard { data: User } envelope.
func (app *ApiServer) v1OAuthMe(c *fiber.Ctx) error {
userId := app.getMyId(c)
if userId == 0 {
wallet := app.getAuthedWallet(c)
id, err := app.getUserIDFromWallet(c.Context(), wallet)
if err != nil {
return fiber.NewError(fiber.StatusUnauthorized, "Could not resolve authenticated user")
}
userId = int32(id)
}

users, err := app.queries.Users(c.Context(), dbv1.GetUsersParams{
Ids: []int32{userId},
MyID: userId,
})
if err != nil {
app.logger.Error("Failed to query user for /oauth/me", zap.Error(err))
return fiber.NewError(fiber.StatusInternalServerError, "Failed to get user info")
}
if len(users) == 0 {
return fiber.NewError(fiber.StatusNotFound, "User not found")
}

user := users[0]
response := fiber.Map{
"userId": user.ID,
"name": user.Name.String,
"handle": user.Handle.String,
"verified": user.IsVerified,
"sub": user.ID,
"iat": time.Now().Unix(),
}
if user.ProfilePicture != nil {
response["profilePicture"] = user.ProfilePicture
}
return c.JSON(response)
}
Loading