Skip to content

Commit ba60659

Browse files
Merge pull request #354 from supertokens/cicd
fix: Fix cicd
2 parents b6a705d + ca1d0d1 commit ba60659

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

.circleci/setupAndTestWithAuthReact.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ git clone git@github.com:supertokens/supertokens-auth-react.git
5454
cd supertokens-auth-react
5555
git checkout $2
5656
npm run init
57-
(cd ./examples/for-tests && npm run link) # this is there because in linux machine, postinstall in npm doesn't work..
5857
cd ./test/server/
5958
npm i -d
6059
npm i git+https://github.com:supertokens/supertokens-node.git#$3

test/frontendIntegration/main.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
package main
1818

1919
import (
20+
"encoding/base64"
2021
"encoding/json"
2122
"fmt"
2223
"io/ioutil"
2324
"net/http"
2425
"os"
2526
"strconv"
2627
"strings"
28+
"time"
2729

2830
"github.com/supertokens/supertokens-golang/recipe/session"
2931
"github.com/supertokens/supertokens-golang/recipe/session/sessmodels"
@@ -170,6 +172,8 @@ func callSTInit(enableAntiCsrf bool, enableJWT bool, jwtPropertyName string) {
170172
setEnableJWT(rw, r)
171173
} else if r.URL.Path == "/login" && r.Method == "POST" {
172174
login(rw, r)
175+
} else if r.URL.Path == "/login-2.18" && r.Method == "POST" {
176+
login218(rw, r)
173177
} else if r.URL.Path == "/beforeeach" && r.Method == "POST" {
174178
beforeeach(rw, r)
175179
} else if r.URL.Path == "/testUserConfig" && r.Method == "POST" {
@@ -411,6 +415,71 @@ func login(response http.ResponseWriter, request *http.Request) {
411415
response.Write([]byte(sess.GetUserID()))
412416
}
413417

418+
func login218(response http.ResponseWriter, request *http.Request) {
419+
var body map[string]interface{}
420+
_ = json.NewDecoder(request.Body).Decode(&body)
421+
422+
userID := body["userId"].(string)
423+
payload := body["payload"].(map[string]interface{})
424+
425+
querier, err := supertokens.GetNewQuerierInstanceOrThrowError("session")
426+
427+
if err != nil {
428+
response.WriteHeader(500)
429+
response.Write([]byte(""))
430+
return
431+
}
432+
433+
supertokens.SetQuerierApiVersionForTests("2.18")
434+
resp, err := querier.SendPostRequest("/recipe/session", map[string]interface{}{
435+
"userId": userID,
436+
"userDataInJWT": payload,
437+
"userDataInDatabase": map[string]interface{}{},
438+
"enableAntiCsrf": false,
439+
})
440+
441+
if err != nil {
442+
response.WriteHeader(500)
443+
response.Write([]byte(""))
444+
return
445+
}
446+
447+
supertokens.SetQuerierApiVersionForTests("")
448+
449+
responseByte, err := json.Marshal(resp)
450+
if err != nil {
451+
response.WriteHeader(500)
452+
response.Write([]byte(""))
453+
return
454+
}
455+
var sessionResp sessmodels.CreateOrRefreshAPIResponse
456+
err = json.Unmarshal(responseByte, &sessionResp)
457+
if err != nil {
458+
response.WriteHeader(500)
459+
response.Write([]byte(""))
460+
return
461+
}
462+
463+
legacyAccessToken := sessionResp.AccessToken.Token
464+
legacyRefreshToken := sessionResp.RefreshToken.Token
465+
466+
frontTokenJson := json.NewEncoder(response).Encode(map[string]interface{}{
467+
"uid": userID,
468+
"ate": uint64(time.Now().UnixNano()/1000000) + 3600000,
469+
"up": payload,
470+
})
471+
472+
parsed, _ := json.Marshal(frontTokenJson)
473+
data := []byte(parsed)
474+
475+
frontToken := base64.StdEncoding.EncodeToString(data)
476+
477+
response.Header().Set("st-access-token", legacyAccessToken)
478+
response.Header().Set("st-refresh-token", legacyRefreshToken)
479+
response.Header().Set("front-token", frontToken)
480+
response.Write([]byte(""))
481+
}
482+
414483
func fail(w http.ResponseWriter, r *http.Request) {
415484
w.WriteHeader(404)
416485
w.Write([]byte(""))

0 commit comments

Comments
 (0)