{"id":2221701,"date":"2022-08-20T15:11:17","date_gmt":"2022-08-20T13:11:17","guid":{"rendered":"http:\/\/nhub.news\/?p=2221701"},"modified":"2022-08-20T23:03:27","modified_gmt":"2022-08-20T21:03:27","slug":"supabase-and-svelte-quickstart-guide","status":"publish","type":"post","link":"http:\/\/nhub.news\/fr\/2022\/08\/supabase-and-svelte-quickstart-guide\/","title":{"rendered":"Supabase and Svelte Quickstart Guide"},"content":{"rendered":"<p style=\"text-align: justify;\"><b>This example provides the steps to build a simple user management app (from scratch!) using Supabase and Svelte.<\/b><br \/>\nJoin the DZone community and get the full member experience.<br \/>This example provides the steps to build a simple user management app (from scratch!) using Supabase and Svelte. It includes:<br \/>By the end of this guide you&rsquo;ll have an app that allows users to log in and update some basic profile details:<br \/>Whenever you get stuck at any point, take a look at this repo.<br \/>Before we start building we&rsquo;re going to set up our Database and API. This is as simple as starting a new Project in Supabase and then creating a \u00ab\u00a0schema\u00a0\u00bb inside the database.<br \/>Go to app.supabase.com.<br \/>Now we are going to set up the database schema. We can use the \u00ab\u00a0User Management Starter\u00a0\u00bb quickstart in the SQL Editor, or you can just copy\/paste the SQL from below and run it yourself.<br \/>Now that you&rsquo;ve created some database tables, you are ready to insert data using the auto-generated API. We just need to get the URL and anon key from the API settings.<br \/>Let&rsquo;s start building the Svelte app from scratch.<br \/>We can use the Quickstart Svelte Template to initialize an app called supabase-svelte:<br \/>Then let&rsquo;s install the only additional dependency: supabase-js<br \/>npm<br \/>Yarn<br \/>And finally, we want to save the environment variables in a .env. All we need are the API URL and the anon key that you copied earlier.<br \/>Our app is almost functional, to make svelte work with supabase and .env files we first need to change the rollup.config.js file a bit. Supabase imports json files, to convert .json files to ES6 modules we need the @rollup\/plugin-json install it by running:<br \/>npm<br \/>Yarn<br \/>and add these plugins to the rollup.config.js file.<br \/>Now that we have the API credentials in place, let&rsquo;s create a helper file to initialize the Supabase client. These variables will be exposed on the browser, and that&rsquo;s completely fine since we have Row Level Security enabled on our Database.<br \/>And one optional step is to update the CSS file public\/global.css to make the app look nice. You can find the full contents of this file here.<br \/>Let&rsquo;s set up a Svelte component to manage logins and sign-ups. We&rsquo;ll use Magic Links, so users can sign in with their email without using passwords.<br \/>To access the user information in other places, we use a writable store. Create a new file called sessionStore.js<br \/>After a user is signed in we can allow them to edit their profile details and manage their account. Let&rsquo;s create a new component for that called Profile.svelte.<br \/>Now that we have all the components in place, let&rsquo;s update App.svelte:<br \/>Once that&rsquo;s done, run this in a terminal window:<br \/>npm<br \/>Yarn<br \/>And then open the browser to localhost:5000 and you should see the completed app.<br \/>\u26a0\ufe0f WARNING: Svelte uses by default port 5000, Supabase uses port 3000. To change the redirection port for supabase go to: Authentication > Settings and change the Site Url to localhost:5000<br \/>Every Supabase project is configured with Storage for managing large files like photos and videos.<br \/>Let&rsquo;s create an avatar for the user so that they can upload a profile photo. We can start by creating a new component:<br \/>And then we can add the widget to the Account page:<br \/>At this stage, you have a fully functional application!<br \/>Published at DZone with permission of Rory Wilding.<br \/> See the original article here.<\/p>\n<p>Opinions expressed by DZone contributors are their own.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This example provides the steps to build a simple user management app (from scratch!) using Supabase and Svelte. Join the DZone community and get the full member experience.This example provides the steps to build a simple user management app (from scratch!) using Supabase and Svelte. It includes:By the end of this guide you&rsquo;ll have an [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2221700,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[93],"tags":[],"_links":{"self":[{"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/posts\/2221701"}],"collection":[{"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/comments?post=2221701"}],"version-history":[{"count":0,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/posts\/2221701\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/media\/2221700"}],"wp:attachment":[{"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/media?parent=2221701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/categories?post=2221701"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/tags?post=2221701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}