Raw
 1package session
 2
 3import (
 4	"context"
 5	"errors"
 6
 7	"tug/internal/storage"
 8)
 9
10func (s *Service) LinkGoogle(ctx context.Context, p Principal, subject string) (storage.GoogleLink, error) {
11	return s.store.LinkGoogleAudited(ctx, storage.CreateGoogleLinkInput{UserID: p.UserID, GoogleSub: subject}, p.SessionID, p.UserID)
12}
13
14func (s *Service) UnlinkGoogle(ctx context.Context, p Principal) (storage.GoogleLink, storage.Revoked, error) {
15	return s.store.UnlinkGoogleAudited(ctx, p.UserID, p.SessionID, p.UserID)
16}
17
18func (s *Service) GoogleLink(ctx context.Context, userID string) (*storage.GoogleLink, error) {
19	link, err := s.store.GoogleLinkByUser(ctx, userID)
20	switch {
21	case errors.Is(err, storage.ErrNotFound):
22		return nil, nil
23	case err != nil:
24		return nil, failure("google link", err)
25	}
26	return &link, nil
27}