Add authentication system with session-based auth
All checks were successful
Build and Push Backend / build (push) Successful in 20s

- Implement register, login, logout, and me endpoints
- Use bcryptjs for password hashing
- HTTPOnly secure cookies for sessions (Lucia Auth pattern)
- Users and sessions tables with proper relations
- 7-day session duration with auto-expiry

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Hector Ros
2026-01-20 01:56:25 +01:00
parent 5672127593
commit 1dc0ab515d
12 changed files with 1226 additions and 1 deletions

View File

@@ -0,0 +1,24 @@
CREATE TABLE `sessions` (
`id` varchar(255) NOT NULL,
`user_id` varchar(36) NOT NULL,
`expires_at` timestamp NOT NULL,
`created_at` timestamp DEFAULT (now()),
CONSTRAINT `sessions_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `users` (
`id` varchar(36) NOT NULL,
`email` varchar(255) NOT NULL,
`username` varchar(100) NOT NULL,
`password_hash` varchar(255) NOT NULL,
`created_at` timestamp DEFAULT (now()),
`updated_at` timestamp DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
CONSTRAINT `users_id` PRIMARY KEY(`id`),
CONSTRAINT `users_email_unique` UNIQUE(`email`),
CONSTRAINT `users_username_unique` UNIQUE(`username`)
);
--> statement-breakpoint
ALTER TABLE `sessions` ADD CONSTRAINT `sessions_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX `idx_user_id` ON `sessions` (`user_id`);--> statement-breakpoint
CREATE INDEX `idx_expires_at` ON `sessions` (`expires_at`);--> statement-breakpoint
CREATE INDEX `idx_email` ON `users` (`email`);