|
| 1 | +--- |
| 2 | +title: Password-based Authentication |
| 3 | +description: Password-based authentication block for Nuxt.js |
| 4 | +--- |
| 5 | + |
| 6 | +<BlockPreview name="password-based-auth/auth/sign-up" /> |
| 7 | + |
| 8 | +## Installation |
| 9 | + |
| 10 | +<BlockItem |
| 11 | + name="password-based-auth-nuxtjs" |
| 12 | + description="All needed components for the password based auth flow" |
| 13 | +/> |
| 14 | + |
| 15 | +## Folder structure |
| 16 | + |
| 17 | +This block assumes that you have already installed a Supabase client for Nuxt from the previous step. |
| 18 | + |
| 19 | +<RegistryBlock itemName="password-based-auth-nuxtjs" /> |
| 20 | + |
| 21 | +## Usage |
| 22 | + |
| 23 | +Once you install the block in your Next.js project, you'll get all the necessary pages and components to set up a password-based authentication flow. |
| 24 | + |
| 25 | +### Getting started |
| 26 | + |
| 27 | +After installing the block, you'll have the following environment variables in your `.env.local` file: |
| 28 | + |
| 29 | +```env |
| 30 | +NUXT_PUBLIC_SUPABASE_URL= |
| 31 | +NUXT_PUBLIC_SUPABASE_PUBLISHABLE_OR_ANON_KEY= |
| 32 | +``` |
| 33 | + |
| 34 | +- If you're using supabase.com, you can find these values in the [Connect modal](https://supabase.com/dashboard/project/_?showConnect=true) under App Frameworks or in your project's [API settings](https://supabase.com/dashboard/project/_/settings/api). |
| 35 | + |
| 36 | +- If you're using a local instance of Supabase, you can find these values by running `supabase start` or `supabase status` (if you already have it running). |
| 37 | + |
| 38 | +### Adding email templates |
| 39 | + |
| 40 | +1. Add an [email template for sign-up](https://supabase.com/dashboard/project/_/auth/templates) to the Supabase project. Your signup email template should contain at least the following HTML: |
| 41 | + |
| 42 | + ```html |
| 43 | + <h2>Confirm your signup</h2> |
| 44 | + |
| 45 | + <p>Follow this link to confirm your user:</p> |
| 46 | + <p> |
| 47 | + <a |
| 48 | + href="{{ .SiteURL }}/auth/confirm?token_hash={{ .TokenHash }}&type=email&next={{ .RedirectTo }}" |
| 49 | + >Confirm your email</a |
| 50 | + > |
| 51 | + </p> |
| 52 | + ``` |
| 53 | + |
| 54 | + For detailed instructions on how to configure your email templates, including the use of variables like `{{ .SiteURL }}`,`{{ .TokenHash }}`, and `{{ .RedirectTo }}`, refer to our [Email Templates guide](https://supabase.com/docs/email-templates). |
| 55 | + |
| 56 | +1. Add an [email template for reset password](https://supabase.com/dashboard/project/_/auth/templates) to the Supabase project. Your reset password email template should contain at least the following HTML: |
| 57 | + |
| 58 | + ```html |
| 59 | + <h2>Reset Password</h2> |
| 60 | + |
| 61 | + <p>Follow this link to reset the password for your user:</p> |
| 62 | + <p> |
| 63 | + <a |
| 64 | + href="{{ .SiteURL }}/auth/confirm?token_hash={{ .TokenHash }}&type=recovery&next={{ .RedirectTo }}" |
| 65 | + >Reset Password</a |
| 66 | + > |
| 67 | + </p> |
| 68 | + ``` |
| 69 | + |
| 70 | +### Setting up routes and redirect URLs |
| 71 | + |
| 72 | +1. Set the site URL in the [URL Configuration](https://supabase.com/dashboard/project/_/auth/url-configuration) settings in the Supabase Dashboard. |
| 73 | +1. Set up the Next.js route that users will visit to reset or update their password. Go to the [URL Configuration](https://supabase.com/dashboard/project/_/auth/url-configuration) settings and add the `forgot-password` route to the list of Redirect URLs. It should look something like: `http://example.com/auth/forgot-password`. |
| 74 | + |
| 75 | +1. Update the redirect paths in `login-form.vue` and `update-password-form.vue` components to point to the logged-in routes in your app. Our examples use `/protected`, but you can set this to whatever fits your app. |
| 76 | + |
| 77 | +## Further reading |
| 78 | + |
| 79 | +- [Password-based authentication (PKCE flow)](https://supabase.com/docs/guides/auth/passwords?queryGroups=flow&flow=pkce) |
| 80 | +- [Authentication error codes](https://supabase.com/docs/guides/auth/debugging/error-codes) |
| 81 | +- [Email templates](https://supabase.com/docs/guides/auth/auth-email-templates) |
| 82 | +- [Email templates for local development](https://supabase.com/docs/guides/local-development/customizing-email-templates) |
| 83 | +- [Custom SMTP](https://supabase.com/docs/guides/auth/auth-smtp) |
0 commit comments