user devices
This commit is contained in:
@@ -8,7 +8,9 @@ import (
|
||||
|
||||
"apskel-pos-be/config"
|
||||
"apskel-pos-be/internal/contract"
|
||||
"apskel-pos-be/internal/entities"
|
||||
"apskel-pos-be/internal/models"
|
||||
"apskel-pos-be/internal/processor"
|
||||
"apskel-pos-be/internal/transformer"
|
||||
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
@@ -24,11 +26,12 @@ type AuthService interface {
|
||||
}
|
||||
|
||||
type AuthServiceImpl struct {
|
||||
userProcessor UserProcessor
|
||||
jwtSecret string
|
||||
refreshSecret string
|
||||
tokenTTL time.Duration
|
||||
refreshTokenTTL time.Duration
|
||||
userProcessor UserProcessor
|
||||
userDeviceProcessor processor.UserDeviceProcessor
|
||||
jwtSecret string
|
||||
refreshSecret string
|
||||
tokenTTL time.Duration
|
||||
refreshTokenTTL time.Duration
|
||||
}
|
||||
|
||||
type Claims struct {
|
||||
@@ -39,13 +42,14 @@ type Claims struct {
|
||||
jwt.RegisteredClaims
|
||||
}
|
||||
|
||||
func NewAuthService(userProcessor UserProcessor, authConfig *config.AuthConfig) AuthService {
|
||||
func NewAuthService(userProcessor UserProcessor, userDeviceProcessor processor.UserDeviceProcessor, authConfig *config.AuthConfig) AuthService {
|
||||
return &AuthServiceImpl{
|
||||
userProcessor: userProcessor,
|
||||
jwtSecret: authConfig.AccessTokenSecret(),
|
||||
refreshSecret: authConfig.RefreshTokenSecret(),
|
||||
tokenTTL: authConfig.AccessTokenTTL(),
|
||||
refreshTokenTTL: authConfig.RefreshTokenTTL(),
|
||||
userProcessor: userProcessor,
|
||||
userDeviceProcessor: userDeviceProcessor,
|
||||
jwtSecret: authConfig.AccessTokenSecret(),
|
||||
refreshSecret: authConfig.RefreshTokenSecret(),
|
||||
tokenTTL: authConfig.AccessTokenTTL(),
|
||||
refreshTokenTTL: authConfig.RefreshTokenTTL(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +85,25 @@ func (s *AuthServiceImpl) Login(ctx context.Context, req *contract.LoginRequest)
|
||||
return nil, fmt.Errorf("failed to generate refresh token: %w", err)
|
||||
}
|
||||
|
||||
// Register or update device info if provided
|
||||
if req.DeviceID != "" && s.userDeviceProcessor != nil {
|
||||
deviceReq := &models.RegisterUserDeviceRequest{
|
||||
UserID: userResponse.ID,
|
||||
DeviceID: req.DeviceID,
|
||||
DeviceName: req.DeviceName,
|
||||
DeviceType: entities.DeviceType(req.DeviceType),
|
||||
Platform: entities.DevicePlatform(req.Platform),
|
||||
FCMToken: req.FCMToken,
|
||||
AppVersion: req.AppVersion,
|
||||
OsVersion: req.OsVersion,
|
||||
}
|
||||
// Non-blocking: log error but don't fail login
|
||||
if _, err := s.userDeviceProcessor.RegisterDevice(ctx, deviceReq); err != nil {
|
||||
// Log but don't fail the login
|
||||
_ = err
|
||||
}
|
||||
}
|
||||
|
||||
return &contract.LoginResponse{
|
||||
Token: token,
|
||||
RefreshToken: refreshToken,
|
||||
|
||||
Reference in New Issue
Block a user