test-sveltekit-web-auth
v0.0.1
Published
A sveltekit library for handling authentication for web3 and web2 providers.
Downloads
3
Readme
2077 Auth
A sveltekit library for handling authentication for web3 and web2 providers.
Installation
// TODO: add actual package name once published
npm install @2077/auth
Usage
The library provides three methods of authentication:
- Browser wallet: connect to a wallet provider
- SIWE + JWT: generates a JWT based on a signature created from a SIWE message
- Web2 providers: Google, X, Github
Browser Wallet
This method connects to a wallet provider and returns the wallet address and chainId.
<script>
import { Auth } from '$lib/index';
</script>
{#snippet header()}
<h4>Connect wallet</h4>
{/snippet}
<Auth
header={header}
walletLoginCallback={(walletInfo) => /*Do something with walletInfo*/}
/>
SIWE + JWT
This method generates a JWT based on a signature created from a SIWE message.
@2077/auth provides the request handlers that will create a SIWE-style messages, forward them to the client, sign the message, and send it back to the server in order to validate and generate a JWT.
// +page.svelte
<script>
import { Auth } from '$lib/index';
export let data;
</script>
{#snippet header()}
<h4>SIWE + JWT</h4>
{/snippet}
<Auth
header={header}
enableSocial={true}
walletLoginCallback={(walletInfo) => /*Do something with walletInfo*/}
signatureEndpoint="/"
authenticationEndpoint="/"
/>
// TODO: rename import to actual package name when published
import { getSignatureMessage, authenticate } from '@2077/auth';
export const GET = getSignatureMessage;
export const POST = authenticate({ jwtSecret: 'secret' });
Web2 Providers
TODO