Authentication - User Accounts
🔐 Authentication
Section titled “🔐 Authentication”Time to add user accounts to GameVault! This way, everyone can have their own personal game collection, and we can keep games private to each user.
Why do we need user accounts? 🤔
Section titled “Why do we need user accounts? 🤔”Right now, anyone who visits our site sees the same games. But what if:
- You want to track YOUR games, not someone else’s
- Multiple people want to use GameVault
- You want to keep your gaming habits private
That’s where user accounts come in! Each person gets their own login and their own game collection.
-
Create the User system 👤
Framefox has a special command that creates everything we need for user authentication. Let’s use the interactive terminal:
Create user authentication system framefox create userThis special command creates everything we need for user accounts:
- A User entity with all the right fields
- Authentication setup and configuration
- Login/signup controllers
- Password security and hashing
- Session management
That’s it! Framefox just set up a complete user system! 🎉
-
Update the database 🛠️
Now we need to add the users table to our database using migrations:
Create user migration framefox database create-migrationApply the changes:
Apply database changes framefox database upgradeGreat! Now your database can store users AND games.
-
Test the login system 🧪
Let’s see our authentication system in action! Framefox created login pages for us.
Start your server if it’s not running:
Start development server framefox runNow visit these URLs:
http://localhost:8000/register
- Create a new accounthttp://localhost:8000/login
- Login page
Try creating an account and logging in. Pretty cool, right?
-
Protect your game pages 🛡️
Right now, anyone can visit your game page without logging in. Let’s add access control to make sure only logged-in users can manage games.
In Framefox, you protect routes by adding them to the
config/security.yaml
file. Create or edit this file and add:config/security.yaml security:access_control:- { path: ^/game, roles: ROLE_USER }This single line tells Framefox: “Only users with ROLE_USER (logged-in users) can access any route starting with
/game
.”That’s it! Now visit
http://localhost:8000/game
:- Not logged in? → Redirected to login page automatically
- Logged in? → See your personal game collection!
Understanding what happened 🎯
Section titled “Understanding what happened 🎯”User Entity
Section titled “User Entity”Stores user information like email, username, and encrypted password using SQLModel.
Authentication System
Section titled “Authentication System”Handles login/logout, password checking, and keeping users logged in using Framefox’s security system.
Access Control with security.yaml
Section titled “Access Control with security.yaml”Your first taste of access control! The security.yaml
file is where you define which pages require login. This clean separation keeps security configuration in one place, separate from your controller logic.
What we accomplished 🏆
Section titled “What we accomplished 🏆”In just a few commands, we added:
- ✅ User registration - People can create accounts
- ✅ Login/logout - Secure access to accounts using authentication
- ✅ Password security - Passwords are encrypted automatically
- ✅ Page protection - Login required to access certain pages using
access_control
rules
Next steps 🚀
Section titled “Next steps 🚀”In the next chapter, we’ll:
- Create a complete game management interface
- Build working forms to add/edit games
- Connect users to their personal game collections
But right now, you have a multi-user web application with secure authentication! That’s professional-level stuff! 🎉
Ready to build the game management system? Let’s move on to Game Management! 🎮✨