Use a proper id for sessions, leave token as a separate field

This commit is contained in:
Zoe Roux 2024-09-02 14:54:59 +02:00
parent b340958348
commit 7b08afde06
No known key found for this signature in database
2 changed files with 4 additions and 3 deletions

View File

@ -78,8 +78,8 @@ func (h *Handler) createSession(c echo.Context, user *User) error {
}
session, err := h.db.CreateSession(ctx, dbc.CreateSessionParams{
ID: base64.StdEncoding.EncodeToString(id),
UserID: user.ID,
Token: base64.StdEncoding.EncodeToString(id),
UserID: user.Id,
Device: device,
})
if err != nil {

View File

@ -1,7 +1,8 @@
begin;
create table sessions(
id varchar(128) not null primary key,
id uuid not null primary key,
token varchar(128) not null unique,
user_id uuid not null references users(id) on delete cascade,
created_date timestamptz not null default now()::timestamptz,
last_used timestamptz not null default now()::timestamptz,