A template to quickly get started with an authenticated Remix application.
- Remix: A modern and flexible framework for building web applications.
- Cloudflare D1: A fast and scalable serverless SQL database.
- Prisma: A powerful and type-safe ORM for database interactions.
- Cloudflare Pages: Efficient hosting with seamless deployment.
- GitHub Authentication: Pre-configured GitHub OAuth strategy for user authentication.
- Extensibility: Easily extendable to support other authentication providers.
- Node.js
- Cloudflare account
- GitHub OAuth app
git clone https://github.com/harshil1712/remix-d1-auth-template.git
cd remix-d1-auth-template
npm install
Rename .dev.vars.example
to .dev.vars
and add the credentials. The file should look as follows:
GITHUB_CLIENT_ID="client_id"
GITHUB_CLIENT_SECRET="client_secret"
COOKIE_SESSION_SECRET="secret"
Generate a new value for
COOKIE_SESSION_SECRET
Follow the Cloudflare D1 documentation to set up your database.
Once the database is created, add the bindings to wrangler.toml
file.
[[d1_databases]]
binding = "DB"
database_name = "DATABASE_NAME"
database_id = "DATABASE_ID"
Generate the Prisma client by running:
npx prisma generate
Apply database migrations,
Locally:
npx wrangler d1 migrations apply DATABASE_NAME --local
Remote (production):
npx wrangler d1 migrations apply DATABASE_NAME --remote
Follow the instructions on the Cloudflare Pages documentation to deploy your Remix app.
To run the application locallly:
npm run dev
You can add support for other providers, or also add username and password auth mechanism to your app. To add other authentication providers (strategy):
npm install remix-auth-STRATEGY
Find the list of all available at this GitHub discussion
Modiy the authentication strategy in app/services/auth.server.ts
.
...
import {NewStrategy} from 'remix-auth-NEW_STRATEGY';
....
this.authenticator.use(new NewStrategy({
// configurations
}, async ()=> {
// insert into table
}))
Add the necessary environment variables for the new provider to you .dev.vars
file.
Based on the new provider added, you might want to store some more information of the user. To do so, you need to update the table. Follow the instructions in the Prisma documentation to learn how to update the schema.
Contributions are welcome! Please open an issue or submit a pull request with your improvements.
- 📖 Remix docs
- 📖 Remix Cloudflare docs
- 📖 Cloudflare D1
- 📖 Prisma
- 📖 Cloudflare Pages
- 📖 Remix Auth
This README.md file was generated with the help of Chat-GPT.