Professional Documents
Culture Documents
Writing An Authentication Store in Svelte - Swyx - Io PDF
Writing An Authentication Store in Svelte - Swyx - Io PDF
Store in Svelte
This is my attempt today wrapping an
Authentication workflow into a Svelte Store
Jan 22 2020
Tech Svelte
https://aws-
amplify.github.io/docs/js/authentication#configure-
your-app
https://github.com/aws-amplify/amplify-
js/blob/master/README.md#2-add-authentication-to-
your-app
// src/main.js
import App from './App.svelte';
Amplify.configure(aws_exports);
// auth.js
import { writable } from 'svelte/store';
And so we have a two line store we can now use in our app.
Let's also create a login component:
<main>
{#if $store != null}
<Main />
{:else}
<Login />
{/if}
</main>
{#await promise}
<p>Logging in...</p>
{:catch error}
<p class="errorMessage">Something went wrong: {error.message}
{/await}
<!-- etc -->
// src/auth.js
import { writable } from 'svelte/store';
import Auth from '@aws-amplify/auth';
// src/auth.js
import { writable } from 'svelte/store';
import Auth from '@aws-amplify/auth';
That's all I've got - even getting here took longer than I
thought! I hope to return to DataStore at some point but
figured I would write up what I have.