Skip to content

Commit

Permalink
add invite link when getting token list
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 committed Mar 10, 2023
1 parent 9f65978 commit 9d81d10
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion internal/http/services/sciencemesh/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,26 @@ func (h *tokenHandler) ListInvite(w http.ResponseWriter, r *http.Request) {
return
}

if err := json.NewEncoder(w).Encode(res.InviteTokens); err != nil {
tokens := make([]*token, 0, len(res.InviteTokens))
user := ctxpkg.ContextMustGetUser(ctx)
for _, tkn := range res.InviteTokens {
inviteURL, err := h.generateInviteLink(user, tkn)
if err != nil {
reqres.WriteError(w, r, reqres.APIErrorServerError, "error generating invite URL from OCM token", err)
return
}
t := &token{
Token: tkn.Token,
Description: tkn.Description,
InviteLink: inviteURL,
}
if tkn.Expiration != nil {
t.Expiration = tkn.Expiration.Seconds
}
tokens = append(tokens, t)
}

if err := json.NewEncoder(w).Encode(tokens); err != nil {
reqres.WriteError(w, r, reqres.APIErrorServerError, "error marshalling token data", err)
return
}
Expand Down

0 comments on commit 9d81d10

Please sign in to comment.