fix auth_token

This commit is contained in:
Nam Huynh 2021-08-19 15:51:09 +07:00
parent 2bfc236555
commit 83b85c2508
3 changed files with 12 additions and 2 deletions

View File

@ -41,6 +41,7 @@ func (s Service) Upsert(payload UpsertPayload) {
appVersionCode = "" appVersionCode = ""
browserName = "" browserName = ""
browserVersion = "" browserVersion = ""
authToken = ""
) )
// Set deviceID // Set deviceID
@ -70,6 +71,13 @@ func (s Service) Upsert(payload UpsertPayload) {
appVersionCode = headerData.AppVersionCode appVersionCode = headerData.AppVersionCode
} }
// Auth token
if headerData.AuthToken != "" {
authToken = headerData.AuthToken
} else {
authToken = payload.AuthToken
}
// pretty.Println("- platform", platform) // pretty.Println("- platform", platform)
// pretty.Println("- osName", osName) // pretty.Println("- osName", osName)
// pretty.Println("- osVersion", osVersion) // pretty.Println("- osVersion", osVersion)
@ -93,7 +101,7 @@ func (s Service) Upsert(payload UpsertPayload) {
).Values( ).Values(
mongodb.NewStringID(), deviceID, payload.IP, platform, appVersion, mongodb.NewStringID(), deviceID, payload.IP, platform, appVersion,
appVersionCode, osName, osVersion, browserName, browserVersion, appVersionCode, osName, osVersion, browserName, browserVersion,
payload.AuthToken, payload.FCMToken, payload.OwnerID, payload.OwnerType, authToken, payload.FCMToken, payload.OwnerID, payload.OwnerType,
payload.FirstSignInAt, now(), payload.FirstSignInAt, now(),
).ToSql() ).ToSql()
@ -114,7 +122,7 @@ func (s Service) Upsert(payload UpsertPayload) {
Set("os_version", osVersion). Set("os_version", osVersion).
Set("browser_name", browserName). Set("browser_name", browserName).
Set("browser_version", browserVersion). Set("browser_version", browserVersion).
Set("auth_token", payload.AuthToken). Set("auth_token", authToken).
Set("fcm_token", payload.FCMToken). Set("fcm_token", payload.FCMToken).
Set("owner_id", payload.OwnerID). Set("owner_id", payload.OwnerID).
Set("owner_type", payload.OwnerType). Set("owner_type", payload.OwnerType).

View File

@ -30,5 +30,6 @@ func getHeaderData(headers http.Header) HeaderData {
AppVersionCode: headers.Get("App-Version-Code"), AppVersionCode: headers.Get("App-Version-Code"),
OSName: headers.Get("Os-Name"), OSName: headers.Get("Os-Name"),
OSVersion: headers.Get("Os-Version"), OSVersion: headers.Get("Os-Version"),
AuthToken: headers.Get("Authorization"),
} }
} }

View File

@ -53,4 +53,5 @@ type HeaderData struct {
AppVersionCode string AppVersionCode string
OSName string OSName string
OSVersion string OSVersion string
AuthToken string
} }