Skip to content

feat: added session id when calling /invite endpoint #2564

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
7 changes: 4 additions & 3 deletions handlers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

type authHandler struct {
db db.Database
makeConnectionCodeRequest func(inviter_pubkey string, inviter_route_hint string, msats_amount uint64) string
makeConnectionCodeRequest func(inviter_pubkey string, inviter_route_hint string, msats_amount uint64, sessionId string) string
decodeJwt func(token string) (jwt.MapClaims, error)
encodeJwt func(pubkey string) (string, error)
}
Expand Down Expand Up @@ -106,7 +106,7 @@ func (ah *authHandler) CreateConnectionCode(w http.ResponseWriter, r *http.Reque
}

for i := 0; i < int(codeBody.Number); i++ {
code := ah.makeConnectionCodeRequest(codeBody.Pubkey, codeBody.RouteHint, codeBody.SatsAmount)
code := ah.makeConnectionCodeRequest(codeBody.Pubkey, codeBody.RouteHint, codeBody.SatsAmount, r.Header.Get("x-session-id"))

if code != "" {
newCode := db.ConnectionCodes{
Expand All @@ -128,7 +128,7 @@ func (ah *authHandler) CreateConnectionCode(w http.ResponseWriter, r *http.Reque
json.NewEncoder(w).Encode("Codes created successfully")
}

func MakeConnectionCodeRequest(inviter_pubkey string, inviter_route_hint string, msats_amount uint64) string {
func MakeConnectionCodeRequest(inviter_pubkey string, inviter_route_hint string, msats_amount uint64, sessionId string) string {
url := fmt.Sprintf("%s/invite", config.V2BotUrl)
client := http.Client{}

Expand All @@ -139,6 +139,7 @@ func MakeConnectionCodeRequest(inviter_pubkey string, inviter_route_hint string,
req, _ := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(jsonBody))
req.Header.Set("x-admin-token", config.V2BotToken)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("x-session-id", sessionId)

res, err := client.Do(req)

Expand Down
2 changes: 1 addition & 1 deletion handlers/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ func TestCreateConnectionCode(t *testing.T) {

aHandler := NewAuthHandler(db.TestDB)

aHandler.makeConnectionCodeRequest = func(inviter_pubkey string, inviter_route_hint string, msats_amount uint64) string {
aHandler.makeConnectionCodeRequest = func(inviter_pubkey string, inviter_route_hint string, msats_amount uint64, sessionId string) string {
return "22222222222222222"
}

Expand Down
Loading