Prisma Auth
A simple, reusable authentication crate supporting both Rocket backend API and Yew frontend authentication components.
Features
- Backend Support: Rocket-based authentication with JWT tokens
- Frontend Support: Yew components for login and authentication guards
- Token Management: Automatic token storage, validation, and expiration
- Modular Design: Use backend, frontend, or both features as needed
Usage
Add to your Cargo.toml:
[]
# For backend (Rocket API)
= { = "../prisma_auth", = ["rocket_backend"] }
# For frontend (Yew WASM)
= { = "../prisma_auth", = ["yew_frontend"] }
# For both
= { = "../prisma_auth", = ["rocket_backend", "yew_frontend"] }
Backend Usage (Rocket)
Basic Setup
use State;
use ;
use ;
Environment Variables
ADMIN_PASSWORD: Required. The admin password for authenticationTOKEN_TTL_SECONDS: Optional. Token expiration time in seconds (default: 600)
Frontend Usage (Yew)
Login Component
use *;
use LoginComponent;
Authentication Guard
use *;
use AuthGuardComponent;
Manual Token Management
use ;
if is_authenticated
// Get the current token
if let Some = get_stored_token
store_token.unwrap;
// Logout (remove stored token)
logout.unwrap;
Making Authenticated API Requests
use ;
// Using stored token automatically
let response = make_authenticated_request.await?;
// Using a specific token
let response = make_request_with_token.await?;
Contributing
Contributions are welcome! Please fork the repository, make your changes, and open a pull request.
- Fork the Project on Forgejo
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
Distributed under the European Union Public License v1.2. See LICENSE for more information.
Contact
Aitor Astorga Saez de Vicuña - a.astorga.sdv@protonmail.com
Project Link: https://git.prisma.moe/aichan/prisma_auth
Acknowledgments
Thanks to these amazing projects and technologies!
- Rust Yew - A modern Rust framework for creating multi-threaded front-end web apps with WebAssembly
- Rocket - A web framework for Rust that makes it simple to write fast, secure web applications
- WebAssembly - A binary instruction format for a stack-based virtual machine