Code Monkey home page Code Monkey logo

remix-auth-totp-cloudflare-example's Introduction

Welcome to Remix Auth TOTP - Remix Auth TOTP Cloudflare Example

This repository is a simple example of how to use Remix Auth TOTP on Cloudflare.

Getting Started

  • Clone the repository and install its dependencies:
pnpm install
  • Get required .dev.vars environment variables for Cloudflare:

This example uses Resend to send emails. You can create a free account and get your API key here. Or you can leave RESEND_API_KEY blank and the example will simulate sending emails.

Note Remember to replace the current .dev.vars.example file with your own .dev.vars file.

  • Run local D1 migrations:
pnpm run d1:migrate:apply
  • Run the server:
pnpm run dev

And you're ready to go! ๐ŸŽ‰

Troubleshooting Local Dev

  • Console spits out 302's continuously. This may occur after rebuilding local from scratch, especially the database, and there are stale cookies in the browser. Clearing cookies for the application in the browser should fix.
[wrangler:inf] GET /verify 302 Found (11ms)
[wrangler:inf] GET /account 302 Found (7ms)
[wrangler:inf] GET /login 302 Found (2ms)
[wrangler:inf] GET /account 302 Found (4ms)
[wrangler:inf] GET /login 302 Found (3ms)
[wrangler:inf] GET /account 302 Found (3ms)
[wrangler:inf] GET /login 302 Found (4ms)

Deployment

  • Go to your Cloudflare account.
  • Use Deplay a Remix Site as reference.
  • Workers & Pages | Overview | Create application button | Pages tab | Connect to Git button
    • Follow the Cloudflare workflow to link the repo.
    • Set up builds and deployments form
      • Framework preset: Remix
      • Build command: pnpm run build
      • Build output directory: build/client
  • Workers & Pages | Overview | remix-auth-totp-cloudflare-example | Settings | Environment variables (for Production and Preview)
    • See .dev.vars.example for reference.
    • ENVIRONMENT = production | preview (ie. specify production for Production and preview for Preview)
    • SESSION_SECRET
    • TOTP_SECRET
    • RESEND_API_KEY
  • Workers & Pages | Overview | remix-auth-totp-cloudflare-example | Settings | Functions | Compatibility date
    • Specify 2024-02-03 for Production and Preview
  • Workers & Pages | Overview | remix-auth-totp-cloudflare-example | Settings | Functions | Compatibility flags
    • Specify nodejs_compat for Production and Preview
  • Workers & Pages | KV | Create a namespace
    • Namespace name: ratce-kv-prod | ratce-kv-preview (ie. create 2 kv's)
  • Workers & Pages | Overview | remix-auth-totp-cloudflare-example | Settings | Functions | KV namespace bindings
    • Production: KV = ratce-kv-prod
    • Preview: KV = ratce-kv-preview
  • Workers & Pages | D1 | Create database | Dashboard
    • Database name: ratce-d1-prod | ratce-d1-preview (ie. create 2 databases)
    • Note database id's for wrangler.toml.
  • Workers & Pages | Overview | remix-auth-totp-cloudflare-example | Settings | Functions | D1 database bindings
    • Production: D1 = ratce-d1-prod
    • Preview: D1 = ratce-d1-preview
  • wrangler.toml
    • [[env.prod.d1_databases]]
      • databse_id = ""
    • [[env.preview.d1_databases]]
      • databse_id = ""
  • Apply migrations
    • pnpm run d1:migrate:apply:prod
    • pnpm run d1:migrate:apply:preview

Etc

pnpm wrangler d1 info ratce-d1-preview
pnpm wrangler d1 info ratce-d1-prod

# dev
pnpm wrangler d1 execute local-d1-dev --local --command "select * from d1_migrations;"
pnpm wrangler d1 execute local-d1-dev --local --command "select * from users;"

# preview
pnpm wrangler d1 execute ratce-d1-preview --command "select * from d1_migrations;"
pnpm wrangler d1 execute ratce-d1-preview --command "select * from users;"

# prod
pnpm wrangler d1 execute ratce-d1-prod --command "select * from d1_migrations;"
pnpm wrangler d1 execute ratce-d1-prod --command "select * from users;"

remix-auth-totp-cloudflare-example's People

Contributors

mw10013 avatar

Stargazers

melodyclue avatar fox avatar Daniel Kanem avatar yuezheng2006 avatar

Watchers

 avatar  avatar

Forkers

tcandens

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.