check expiry
This commit is contained in:
parent
4a756e850e
commit
1fce6f6a48
@ -55,14 +55,15 @@ func (m *DBModel) InsertToken(t *Token, u User) error {
|
||||
}
|
||||
|
||||
stmt = `INSERT INTO tokens
|
||||
(user_id, name, email, token_hash, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?)`
|
||||
(user_id, name, email, token_hash, expiry_at, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)`
|
||||
|
||||
_, err = m.DB.ExecContext(ctx, stmt,
|
||||
u.ID,
|
||||
u.LastName,
|
||||
u.Email,
|
||||
t.Hash,
|
||||
t.Expiry,
|
||||
time.Now(),
|
||||
time.Now(),
|
||||
)
|
||||
@ -82,9 +83,9 @@ func (m *DBModel) GetUserForToken(token string) (*User, error) {
|
||||
query := `SELECT u.id, u.first_name, u.last_name, u.email
|
||||
FROM users u
|
||||
INNER JOIN tokens t on (u.id = t.user_id)
|
||||
WHERE t.token_hash = ?`
|
||||
WHERE t.token_hash = ? AND t.expiry_at > ?`
|
||||
|
||||
err := m.DB.QueryRowContext(ctx, query, tokenHash[:]).Scan(
|
||||
err := m.DB.QueryRowContext(ctx, query, tokenHash[:], time.Now()).Scan(
|
||||
&user.ID,
|
||||
&user.FirstName,
|
||||
&user.LastName,
|
||||
|
1
migrations/20240819202607_add_token_expiry.down.fizz
Normal file
1
migrations/20240819202607_add_token_expiry.down.fizz
Normal file
@ -0,0 +1 @@
|
||||
drop_column("tokens, "expiry_at")
|
2
migrations/20240819202607_add_token_expiry.up.fizz
Normal file
2
migrations/20240819202607_add_token_expiry.up.fizz
Normal file
@ -0,0 +1,2 @@
|
||||
add_column("tokens", "expiry_at", "timestamp", {})
|
||||
|
Loading…
Reference in New Issue
Block a user