Skip to content

Latest commit

 

History

History
110 lines (78 loc) · 2.57 KB

File metadata and controls

110 lines (78 loc) · 2.57 KB

Features

  • Consistency across sessions: When a user logs in with multiple devices having different sessions, the user data will stay consistent across all devices upon reload.
  • Cookies are not directly stored in database. Cookies are signed with the SECRET_KEY and the unsigned version is stored in database.
  • Auto Refreshing Sessions: If a user tries to log in within 7 days after the session has expired then the user is automatically logged back in.

Limitations & Use Cases

  • This server is dependent on moka (a fast, concurrent cache library) instead of other key value databases like redis, memcached, valkey, dragonfly, etc. So using load balancers without session affinity (sticky sessions) will break the origin servers
  • The session affinity ttl (Time to Live) must be equal to util::session::Session::MEM_CACHE_DURATION for consistency

Build and Run

Step 1: Connect to postgreql, create an user and a database

sudo -u postgres psql
CREATE DATABASE mydb;
CREATE USER myuser WITH PASSWORD 'mypassword';
GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
\c mydb
ALTER SCHEMA public OWNER TO myuser;

Your DATABASE_URL=postgresql://myuser:mypassword@127.0.0.1:5432/mydb

Step 2: Create a .env file inside project root, and set the following environment variables inside .env file

SOCKET=your_ip:your_port
SECRET_KEY=your_secret_key_for_signing_cookies
SERVICE_NAME=your_service_name
SERVICE_DOMAIN=your_service_domain_with_scheme

# Database
DATABASE_URL=your_postgres_database_url

# Object Storage
BUCKET_ACCESS_KEY=your_bucket_access_key
BUCKET_SECRET_KEY=your_bucket_secret_key
BUCKET_ID=your_bucket_id
BUCKET_ENDPOINT=your_bucket_endpoint
BUCKET_NAME=your_bucket_name
BUCKET_REGION=your_bucket_region
BUCKET_PUBLIC_URL=your_bucket_public_url

# Email
SMTP_KEY=your_smtp_key
SMTP_HOST=your_smtp_host
NOREPLY_EMAIL=your_noreply_email

# OAuth
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret

Step 3: Run database migrations

For installation use cargo install sqlx-cli

sqlx migrate run --source .migrations
cargo sqlx prepare --workspace

Step 4: Run your project

For installation use cargo install dioxus-cli

For client side rendering, use

dx serve --server --port 8080 --bin app-csr

For server side rendering, use

dx serve --server --port 8080 --bin app-ssr

Run without dioxus-cli

cargo run --features server

or (for hot reloading)

cargo watch -x run --features server