From 83b85c250805d91475c5a0d4a25f4969300e07c4 Mon Sep 17 00:00:00 2001 From: Nam Huynh Date: Thu, 19 Aug 2021 15:51:09 +0700 Subject: [PATCH] fix auth_token --- action_upsert.go | 12 ++++++++++-- helper.go | 1 + model.go | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/action_upsert.go b/action_upsert.go index 10e9370..00b5429 100644 --- a/action_upsert.go +++ b/action_upsert.go @@ -41,6 +41,7 @@ func (s Service) Upsert(payload UpsertPayload) { appVersionCode = "" browserName = "" browserVersion = "" + authToken = "" ) // Set deviceID @@ -70,6 +71,13 @@ func (s Service) Upsert(payload UpsertPayload) { appVersionCode = headerData.AppVersionCode } + // Auth token + if headerData.AuthToken != "" { + authToken = headerData.AuthToken + } else { + authToken = payload.AuthToken + } + // pretty.Println("- platform", platform) // pretty.Println("- osName", osName) // pretty.Println("- osVersion", osVersion) @@ -93,7 +101,7 @@ func (s Service) Upsert(payload UpsertPayload) { ).Values( mongodb.NewStringID(), deviceID, payload.IP, platform, appVersion, appVersionCode, osName, osVersion, browserName, browserVersion, - payload.AuthToken, payload.FCMToken, payload.OwnerID, payload.OwnerType, + authToken, payload.FCMToken, payload.OwnerID, payload.OwnerType, payload.FirstSignInAt, now(), ).ToSql() @@ -114,7 +122,7 @@ func (s Service) Upsert(payload UpsertPayload) { Set("os_version", osVersion). Set("browser_name", browserName). Set("browser_version", browserVersion). - Set("auth_token", payload.AuthToken). + Set("auth_token", authToken). Set("fcm_token", payload.FCMToken). Set("owner_id", payload.OwnerID). Set("owner_type", payload.OwnerType). diff --git a/helper.go b/helper.go index 049d93b..23f9070 100644 --- a/helper.go +++ b/helper.go @@ -30,5 +30,6 @@ func getHeaderData(headers http.Header) HeaderData { AppVersionCode: headers.Get("App-Version-Code"), OSName: headers.Get("Os-Name"), OSVersion: headers.Get("Os-Version"), + AuthToken: headers.Get("Authorization"), } } diff --git a/model.go b/model.go index 78b0c35..d492fcd 100644 --- a/model.go +++ b/model.go @@ -53,4 +53,5 @@ type HeaderData struct { AppVersionCode string OSName string OSVersion string + AuthToken string }