All Projects → srmullen → sveltekit-magic

srmullen / sveltekit-magic

Licence: other
An implementation of passwordless authentication using Magic with SvelteKit.

Programming Languages

Svelte
593 projects
typescript
32286 projects
CSS
56736 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects
shell
77523 projects

Projects that are alternatives of or similar to sveltekit-magic

website
Gitpod website and documentation
Stars: ✭ 233 (+513.16%)
Mutual labels:  svelte, sveltekit
sveltekit-blog
Sveltekit blog starter project created with sveltekit, typescript, tailwindcss, postcss, husky, and storybook. The project has the structure set up for the scaleable web application.
Stars: ✭ 100 (+163.16%)
Mutual labels:  svelte, sveltekit
hue.tools
Simple toolbox for working with colors. Color mixing, blending, conversion, modification, detailed information, etc.
Stars: ✭ 331 (+771.05%)
Mutual labels:  svelte, sveltekit
hagura-sveltekit
A minimal markdown blog template built using SvelteKit
Stars: ✭ 51 (+34.21%)
Mutual labels:  svelte, sveltekit
sveltekit-blog-template
A SvelteKit blog template
Stars: ✭ 79 (+107.89%)
Mutual labels:  svelte, sveltekit
kickstart
Ruby on Rails application templates
Stars: ✭ 61 (+60.53%)
Mutual labels:  svelte, sveltekit
focus-svelte
focus lock for svelte
Stars: ✭ 18 (-52.63%)
Mutual labels:  svelte, sveltekit
svelte-parallax
a (small) spring-based parallax component library for Svelte
Stars: ✭ 87 (+128.95%)
Mutual labels:  svelte, sveltekit
turbosvelte
A SvelteKit monorepo starter project powered by Turborepo!
Stars: ✭ 47 (+23.68%)
Mutual labels:  svelte, sveltekit
awesome-svelte-kit
Curated resources on building sites with SvelteKit - A server-less-first answer to "the Next.js experience" by the Svelte community
Stars: ✭ 55 (+44.74%)
Mutual labels:  svelte, sveltekit
webstone
Start your next full-stack application with Webstone and configure it as you go.
Stars: ✭ 71 (+86.84%)
Mutual labels:  svelte, sveltekit
Beatbump
Alternative YouTube Music frontend built with Svelte/SvelteKit 🎧
Stars: ✭ 77 (+102.63%)
Mutual labels:  svelte, sveltekit
website
🏡 My personal website! Now built with Svelte...
Stars: ✭ 18 (-52.63%)
Mutual labels:  svelte, sveltekit
svelte-toy
A toy for svelte data stores
Stars: ✭ 73 (+92.11%)
Mutual labels:  svelte, sveltekit
sveltekit-electron
Minimal Sveltekit + Electron starter template.
Stars: ✭ 146 (+284.21%)
Mutual labels:  svelte, sveltekit
svelte-starter-kit
Svelte with brilliant bells and useful whistles
Stars: ✭ 384 (+910.53%)
Mutual labels:  svelte, sveltekit
svelte-adapter-deno
A SvelteKit adapter for Deno
Stars: ✭ 152 (+300%)
Mutual labels:  svelte, sveltekit
generator-jhipster-svelte
Generate Svelte powered JHipster web applications
Stars: ✭ 44 (+15.79%)
Mutual labels:  svelte, sveltekit
programmingtil-svelte
No description or website provided.
Stars: ✭ 59 (+55.26%)
Mutual labels:  svelte, sveltekit
markushatvan.com
Personal website and blog written from scratch with SvelteKit and TailwindCSS.
Stars: ✭ 82 (+115.79%)
Mutual labels:  svelte, sveltekit

sveltekit-magic

This is a demo application for using Magic auth with SvelteKit. Magic provides secure, passwordless authentication for your application.

See it in action here: https://sveltekit-magic.netlify.app/

How it works

When a user wants to log into the app they will click on the LOGIN link in the header. This will bring them to a page that displays the login form. There is separate signup and login pages. They are all the same. There is also no password field to fill out on this page. That greatly reduces friction when signing up/logging into the application because the user doesn't need to create or remember their passwords. When the user submits their email a link will be sent to them. Clicking on the link will log them into the application and the signup page (assuming the user didn't close it) will naviate to the todos page, which is the protected page of the application.

While that is happening, the Magic SDK generates a DID token (Decentralized Identifier) that gets sent to a SvelteKit endpoint for validation. This routes/api/auth/login endpoint validates the token and gets some metadata about the user. This metadata is added to a cookie that gets sent to the user so we can reconize the user on subsequent requests.

On the frontend we check to see if a user is logged-in in the top-level __layout.svelte component's, load function. This function calls the routes/api/auth/user endpoint which returns the user info and refreshes the cookie if the user is logged in, otherwise it doesn't return anything. That information gets put into an authentication store, which can be checked to see if the client is logged in or not. The todos/__layout.svelte component's load function (this load function runs after the top-level load function) checks that store for a user, and renders the page if it exists. If the user doesn't exist a redirect response is returned and the client is sent to the login page. Because this happens in a load function this can happen either client-side or server-side.

The client can now create todos. Every request made for a SvelteKit app runs through the handle function defined in hooks.ts. In this function the session cookie is read to get the user metadata which set on the request.locals object. This metadata contains a publicAddress which here is used like an id for identifying the user.

When the user logs out, by clicking on the LOGOUT link, a request to the routes/api/auth/logout endpoint is made, which invalidates the session cookie and logs out the user on Magic (by default they stay logged in on Magic for seven days).

Run it yourself

  1. Sign up for a Magic account.
  2. Rename .env.example to .env
  3. Populate the variables in the .env file.
  4. Start the development server npm run dev.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].