setup project

This commit is contained in:
2026-04-04 13:35:33 -06:00
parent 3f75aead20
commit 27088c2cd8
48 changed files with 7831 additions and 2 deletions

58
backend/service/auth.go Normal file
View File

@@ -0,0 +1,58 @@
package service
import (
"context"
"errors"
"git.nmcnew.com/nmcnew/bracketeer/db"
"golang.org/x/crypto/bcrypt"
)
var (
ErrAuthFailed = errors.New("auth values don't match")
)
type AuthService interface {
Login(ctx context.Context, username string, authValue string, authType string) (*db.User, error)
}
type authService struct {
q *db.Queries
}
func NewAuthService(q *db.Queries) AuthService {
return &authService{
q: q,
}
}
func (s *authService) Login(ctx context.Context, username, authValue, authType string) (*db.User, error) {
dbValue, err := s.q.GetUserAuthValue(ctx, db.GetUserAuthValueParams{
Name: username,
Type: db.AuthTypeFromString(authType),
})
if err != nil {
return nil, err
}
switch authType {
case "password":
err = bcrypt.CompareHashAndPassword([]byte(dbValue.AuthValue), []byte(authValue))
if err != nil {
return nil, ErrAuthFailed
}
default:
if authValue != dbValue.AuthValue {
return nil, ErrAuthFailed
}
user, err := s.q.GetUserFromId(ctx, dbValue.UserID)
if err != nil {
return nil, err
}
return &user, nil
}
return nil, ErrAuthFailed
}
func (s *authService) Register(ctx context.Context, username, email, bio, profileURL, authValue, authType string) (*db.User, error) {
panic("unimplemented")
}