Make google authentication to ersteller-lib

This commit is contained in:
Achim Rohn
2025-09-17 20:58:53 +02:00
parent c4f4c5d637
commit b788fb4898
3 changed files with 62 additions and 32 deletions
+32
View File
@@ -0,0 +1,32 @@
package google
import (
"context"
ersteller_lib "ersteller-lib"
google_http "ersteller-lib/authentication/google/http"
"ersteller-lib/starter/ent"
"ersteller-lib/starter/ent/user"
)
type Database struct {
db *ent.Client
}
func NewDatabase(db *ent.Client) google_http.Database {
return &Database{
db: db,
}
}
func (d *Database) GetUserIdByEmail(ctx context.Context, email string) (int, error) {
return d.db.User.Query().Where(user.Email(email)).OnlyID(ctx)
}
func (d *Database) CreateUser(ctx context.Context, email string) (int, error) {
newUser, err := d.db.User.Create().SetEmail(email).Save(ctx)
if err != nil {
ersteller_lib.LogError("Failed to create user: %v", err)
return -1, err
}
return newUser.ID, nil
}