You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/README.md
+67-57Lines changed: 67 additions & 57 deletions
Original file line number
Diff line number
Diff line change
@@ -4,28 +4,28 @@ Welcome to the Remix Auth TOTP Documentation!
4
4
5
5
## List of Contents
6
6
7
-
-[Live Demo](https://totp.devxo.workers.dev) - A live demo that displays the authentication flow.
8
-
-[Getting Started](https://github.com/dev-xo/remix-auth-totp/tree/main/docs#getting-started) - A quick start guide to get you up and running.
9
-
-[Examples](https://github.com/dev-xo/remix-auth-totp/blob/main/docs/examples.md) - A list of community examples using Remix Auth TOTP.
10
-
-[Customization](https://github.com/dev-xo/remix-auth-totp/blob/main/docs/customization.md) - A detailed guide of all the available options and customizations.
11
-
-[Cloudflare](https://github.com/dev-xo/remix-auth-totp/blob/main/docs/cloudflare.md) - A guide to using Remix Auth TOTP with Cloudflare Workers.
7
+
-[Live Demo](https://totp.devxo.workers.dev) - See it in action.
For a simple implementation, check out the [Remix Starter Example](https://github.com/dev-xo/totp-starter-example/blob/main/app/modules/email/email.server.ts), which provides a clean and straightforward `sendEmail` function using [Resend](https://resend.com).
59
-
60
-
This implementation works with both Remix and React Router v7 applications.
70
+
For a working example, see the [Remix Saas - Email](https://github.com/dev-xo/remix-saas/blob/main/app/lib/email/email.server.ts) implementation using Resend API.
61
71
62
72
## Session Storage
63
73
64
-
We'll require to initialize a new Session Storage to work with. This Session will store user data and everything related to authentication.
65
-
66
-
Create a file called `session.server.ts` wherever you want.<br />
67
-
Implement the following code and replace the `secrets` property with a strong string into your `.env` file.
68
-
69
-
Same applies for Remix or React Router v7.
74
+
We'll require to initialize a new Session Storage to work with. This Session will store user data and everything related to the TOTP authentication.
70
75
71
76
```ts
72
-
// app/modules/auth/session.server.ts
73
-
import { createCookieSessionStorage } from'@remix-run/node'// Or 'react-router'.
77
+
// app/lib/auth-session.server.ts
78
+
import { createCookieSessionStorage } from'react-router'// Or '@remix-run'.
@@ -92,28 +97,25 @@ Now that we have everything set up, we can start implementing the Strategy Insta
92
97
93
98
### 1. Implementing the Strategy Instance.
94
99
95
-
Create a file called `auth.server.ts` wherever you want. <br />
96
-
97
100
> [!IMPORTANT]
98
-
> A random 64-character hexadecimal string is required to generate the TOTP codes. This string should be stored securely and not shared with anyone.
101
+
> A random 64-character hexadecimal string is required to generate the TOTP codes.
99
102
> You can use a site like https://www.grc.com/passwords.htm to generate a strong secret.
100
103
101
-
Implement the following code and replace the `secret` property with a string containing exactly 64 random hexadecimal characters (0-9 and A-F) into your `.env` file. An example is `928F416BAFC49B969E62052F00450B6E974B03E86DC6984D1FA787B7EA533227`.
104
+
Add a 64-character hex string (0-9, A-F) as the `secret` property in your `.env` file. Example:
> You can customize the cookie behavior by passing `cookieOptions` to the `sessionStorage` instance. Check [Customization](https://github.com/dev-xo/remix-auth-totp/blob/main/docs/customization.md) to learn more.
136
+
> You can customize the cookie behavior by passing `cookieOptions` to the `TOTPStrategy` instance. Check [Customization](https://github.com/dev-xo/remix-auth-totp/blob/main/docs/customization.md) to learn more.
135
137
136
138
### 2: Implementing the Strategy Logic.
137
139
@@ -143,8 +145,8 @@ authenticator.use(
143
145
{
144
146
...
145
147
sendTOTP: async ({ email, code, magicLink }) => {
146
-
// Send the TOTP code to the user.
147
-
awaitsendEmail({ email, code, magicLink })
148
+
// Send email with TOTP code.
149
+
awaitsendAuthEmail({ email, code, magicLink })
148
150
},
149
151
},
150
152
async ({ email }) => {},
@@ -156,6 +158,8 @@ authenticator.use(
156
158
157
159
The Strategy returns a `verify` method that allows handling our own logic. This includes creating the user, updating the session, etc.<br />
158
160
161
+
When using Cloudflare D1, you may want to perform the lookup in `action` or `loader` after committing the session, by passing the `context` binding to a `findOrCreateUserByEmail` function.
162
+
159
163
This should return the user data that will be stored in Session.
160
164
161
165
```ts
@@ -198,23 +202,21 @@ authenticator.use(
198
202
199
203
## Auth Routes
200
204
201
-
Last but not least, we'll require to create the routes that will handle the authentication flow. Create the following files inside the `app/routes` folder.
Done! 🎉 Feel free to check the [Starter Example for React Router v7](https://github.com/dev-xo/remix-auth-totp-v4-starter) for a detailed implementation.
443
+
## Next Steps
444
+
445
+
🎉 Done! You've completed the basic setup.
446
+
447
+
For a complete implementation example, check out the [React Router v7 Starter Template](https://github.com/dev-xo/remix-auth-totp-v4-starter).
448
+
449
+
## Configuration Options
440
450
441
-
## [Options and Customization](https://github.com/dev-xo/remix-auth-totp/blob/main/docs/customization.md)
451
+
The TOTP Strategy can be customized with various options to fit your needs. See the [customization documentation](https://github.com/dev-xo/remix-auth-totp/blob/main/docs/customization.md) for:
442
452
443
-
The Strategy includes a few options that can be customized.
453
+
## Support
444
454
445
-
You can find a detailed list of all the available options in the [customization](https://github.com/dev-xo/remix-auth-totp/blob/main/docs/customization.md) documentation.
455
+
If you found **Remix Auth TOTP** helpful, please consider supporting it with a ⭐ [Star](https://github.com/dev-xo/remix-auth-totp).
Copy file name to clipboardExpand all lines: docs/examples.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -4,14 +4,14 @@ A list of community examples using Remix Auth TOTP.
4
4
5
5
## v4.0 Examples
6
6
7
-
-[React Router v7 - Starter](https://github.com/dev-xo/remix-auth-totp-v4-starter) by [@dev-xo](https://github.com/dev-xo): A straightforward database-less example App. It can also serve as a foundation for your Remix App or other projects.
7
+
-[React Router v7 - Starter](https://github.com/dev-xo/remix-auth-totp-v4-starter) by [@dev-xo](https://github.com/dev-xo): A straightforward database-less example App. It can also serve as a foundation for your RR7 App or other projects.
8
8
-[React Router v7 - Drizzle ORM](https://github.com/CyrusVorwald/react-router-playground) by [@CyrusVorwald](https://github.com/CyrusVorwald): A simple to start, Drizzle + PostgreSQL example, that aims to be a playground for your React Router v7 app.
9
9
10
10
## v3.0 Examples
11
11
12
12
These are examples for the v3.0+ release. The implementation is mostly compatible with v4.0, with slight differences in how the session is handled.
13
13
14
-
-[Remix Auth TOTP - Starter](https://github.com/dev-xo/totp-starter-example) by [@dev-xo](https://github.com/dev-xo): A straightforward Prisma ORM + SQLite example App. It can also serve as a foundation for your own projects or other examples.
14
+
-[Remix Auth TOTP - Starter](https://github.com/dev-xo/totp-starter-example) by [@dev-xo](https://github.com/dev-xo): A straightforward Prisma ORM + SQLite example App. It can also serve as a foundation for your Remix App or other projects.
15
15
-[Remix Auth TOTP + Remix Flat Routes](https://github.com/dev-xo/totp-flat-routes-example) by [@dev-xo](https://github.com/dev-xo): Remix Auth TOTP + Remix Flat Routes example App.
16
16
-[Remix Auth TOTP + Conform](https://github.com/dev-xo/totp-conform-example) by [@dev-xo](https://github.com/dev-xo): Remix Auth TOTP + Conform example App.
17
17
-[Remix Auth TOTP + Cloudflare](https://github.com/mw10013/remix-auth-totp-cloudflare-example) by [@mw10013](https://github.com/mw10013): Remix Auth TOTP + Cloudflare example App.
0 commit comments