36 lines
992 B
Go
36 lines
992 B
Go
package sresponse
|
|
|
|
import (
|
|
customermodel "git.sendico.io/tech/sxchnge/product/customers/model"
|
|
"net/http"
|
|
|
|
"git.sendico.io/tech/sxchnge/product/sessions/browser"
|
|
"git.sendico.io/tech/sxchnge/shared/http/response"
|
|
"git.sendico.io/tech/sxchnge/shared/logging"
|
|
)
|
|
|
|
type loginResponse struct {
|
|
accountResponse
|
|
RefreshToken TokenData `json:"refreshToken"`
|
|
}
|
|
|
|
func Login(logger mlogger.Logger, account *customermodel.Account, accessToken, refreshToken *TokenData) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
responseRefreshToken := *refreshToken
|
|
if browser.UsesCookie(r) {
|
|
browser.SetRefreshCookie(w, r, refreshToken.Token, refreshToken.Expiration)
|
|
responseRefreshToken.Token = ""
|
|
}
|
|
response.Ok(
|
|
logger,
|
|
&loginResponse{
|
|
accountResponse: accountResponse{
|
|
Account: *NewAccountData(account),
|
|
authResponse: authResponse{AccessToken: *accessToken},
|
|
},
|
|
RefreshToken: responseRefreshToken,
|
|
},
|
|
).ServeHTTP(w, r)
|
|
}
|
|
}
|