Skip to content

Instantly share code, notes, and snippets.

Avatar
🦀
friendly rustacean

Roberto Huertas robertohuertasm

🦀
friendly rustacean
View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am robertohuertasm on github.
  • I am robertohuertasm (https://keybase.io/robertohuertasm) on keybase.
  • I have a public key ASDpvIt8m-C06M2ZPwPtlAKy4nfh9ddOS3hb4FFPiVgHGQo

To claim this, I am signing this object:

View sveltekit-cognito.index.svelte
<script>
import { signOut as authSignOut } from 'sk-auth/client';
import { session } from '$app/stores';
// getting the user from the session store
$: user = $session.user;
function signIn() {
location.assign('/api/auth/signin/cognito?redirect=/');
}
View sveltekit-cognito.hooks.js
import { appAuth } from '$lib/auth';
export const { getSession } = appAuth;
View sveltekit-cognito.[...auth].js
// we're importing our auth object here
import { appAuth } from '$lib/auth';
// and exposing the get and post method handlers
export const { get, post } = appAuth;
View sveltekit-cognito.env
VITE_CLIENT_ID=<your_client_id>
VITE_CLIENT_SECRET=<your_client_secret>
View sveltekit-cognito.auth.js
import { SvelteKitAuth, Providers } from 'sk-auth';
// this is the domain we set up in our Cognito Pool
const DOMAIN = 'sveltekit.auth.eu-west-1.amazoncognito.com';
// these are the configuration seetings for our OAUTH2 provider
const config = {
accessTokenUrl: `https://${DOMAIN}/oauth2/token`,
profileUrl: `https://${DOMAIN}/oauth2/userInfo`,
authorizationUrl: `https://${DOMAIN}/oauth2/authorize`,
View sveltekit-cognito.ui.svelte
<script>
// we'll edit this later
let user;
</script>
<svelte:head>
<title>SvelteKit - Cognito</title>
</svelte:head>
{#if !user}
View sveltekit-cognito.init.sh
npm init svelte@next sveltekit-cognito-auth
# I'm choosing the Skeleton project,
# opting out of TypeScript for this tutorial
# and using ESlint and Prettier support
cd sveltekit-cogniton-auth
npm install