Add Device Token Support for Customer and User Entities
- Introduced a new DeviceToken field in both Customer and User entities to store device tokens for authentication and notifications. - Updated LoginForm structures for both Customer and User to include an optional DeviceToken field, allowing clients to send device tokens during login. - Enhanced the Login methods in the customer and user services to append the device token to the respective entities if it does not already exist, improving user session management and notification capabilities. - Ensured proper validation and structured responses for the new DeviceToken field in the forms, maintaining compliance with best practices for API design.
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -529,6 +530,11 @@ func (s *customerService) Login(ctx context.Context, form *LoginForm) (*AuthResp
|
||||
return nil, errors.New("failed to generate authentication tokens")
|
||||
}
|
||||
|
||||
// append device token to customer if not exists
|
||||
if !slices.Contains(customer.DeviceToken, form.DeviceToken) {
|
||||
customer.DeviceToken = append(customer.DeviceToken, form.DeviceToken)
|
||||
}
|
||||
|
||||
err = s.repository.Login(ctx, customer.ID.Hex())
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to update customer last login", map[string]interface{}{
|
||||
|
||||
Reference in New Issue
Block a user