-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.go
40 lines (32 loc) · 1022 Bytes
/
create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package service
import (
"time"
"github.com/pkg/errors"
"github.com/artem-malko/auth-and-go/constants"
"github.com/artem-malko/auth-and-go/infrastructure/database"
"github.com/artem-malko/auth-and-go/models"
"github.com/google/uuid"
)
func (s *sessionService) CreateSession(
executor database.QueryExecutor,
accountID, identityID uuid.UUID,
clientID models.ClientID,
) (*models.Session, error) {
session := models.Session{
AccountID: accountID,
IdentityID: identityID,
ID: uuid.New(),
ClientID: clientID,
AccessToken: uuid.New(),
AccessTokenExpiresDate: time.Now().
Add(time.Second * time.Duration(constants.Values.AccessTokenMaxAgeInSeconds)),
RefreshToken: uuid.New(),
RefreshTokenExpiresDate: time.Now().
Add(time.Second * time.Duration(constants.Values.RefreshTokenMaxAgeInSeconds)),
}
err := s.sessionRepository.CreateSession(executor, session)
if err != nil {
return nil, errors.Wrap(err, "session service: CreateSession error")
}
return &session, nil
}