version 1
Build and Deploy / test-backend (push) Successful in 1m11s
Build and Deploy / lint-frontend (push) Successful in 21s
Build and Deploy / build-backend (push) Successful in 58s
Build and Deploy / deploy (push) Canceled after 0s
Build and Deploy / build-frontend (push) Canceled after 5m38s
Build and Deploy / test-backend (push) Successful in 1m11s
Build and Deploy / lint-frontend (push) Successful in 21s
Build and Deploy / build-backend (push) Successful in 58s
Build and Deploy / deploy (push) Canceled after 0s
Build and Deploy / build-frontend (push) Canceled after 5m38s
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/dusiburg/fancy-api/internal/model"
|
||||
"github.com/dusiburg/fancy-api/internal/provider/kotosoft"
|
||||
"github.com/dusiburg/fancy-api/internal/repository"
|
||||
)
|
||||
|
||||
type AuthService struct {
|
||||
kotosoft *kotosoft.Client
|
||||
users *repository.UserRepository
|
||||
sessions *SessionService
|
||||
}
|
||||
|
||||
func NewAuthService(kotosoft *kotosoft.Client, users *repository.UserRepository, sessions *SessionService) *AuthService {
|
||||
return &AuthService{kotosoft: kotosoft, users: users, sessions: sessions}
|
||||
}
|
||||
|
||||
func (s *AuthService) CreateSession(ctx context.Context, accessToken string) (string, error) {
|
||||
profile, err := s.kotosoft.GetUserInfo(ctx, accessToken)
|
||||
if err != nil {
|
||||
return "", ErrKotosoftUnauthorized
|
||||
}
|
||||
|
||||
user, err := s.users.UpsertByKotosoftID(ctx, profile.ID, profile.Email, profile.FirstName, profile.SecondName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return s.sessions.Create(ctx, user.Id)
|
||||
}
|
||||
|
||||
func (s *AuthService) GetUser(ctx context.Context, userID uuid.UUID) (*model.User, error) {
|
||||
return s.users.GetByID(ctx, userID)
|
||||
}
|
||||
|
||||
func (s *AuthService) RevokeSession(ctx context.Context, token string) error {
|
||||
return s.sessions.Revoke(ctx, token)
|
||||
}
|
||||
Reference in New Issue
Block a user