| 3121 | const SessionTTL = 7 * 24 * time.Hour |
| 3122 | |
| 3123 | func (s *Store) CreateUserSession(ctx context.Context, userID string) (string, error) { |
| 3124 | token := "sess_" + randomHex32() // opaque session cookie value |
| 3125 | expiresAt := time.Now().Add(SessionTTL) |
| 3126 | _, err := s.pool.Exec(ctx, |
| 3127 | `INSERT INTO user_sessions (token, user_id, created_at, expires_at) VALUES ($1, $2, $3, $4)`, |
| 3128 | token, userID, time.Now(), expiresAt, |
| 3129 | ) |
| 3130 | if err != nil { |
| 3131 | return "", err |
| 3132 | } |
| 3133 | return token, nil |
| 3134 | } |
| 3135 | |
| 3136 | func (s *Store) GetUserSession(ctx context.Context, token string) (*User, error) { |
| 3137 | u := &User{} |