Skip to content

Frameworks ​

Every framework package does two things:

  1. Wraps <sigport-signin> and <sigport-button> as native components.
  2. Binds the headless store to the framework's own reactivity, for your own UI.

The React, Vue and Svelte wrappers register the custom elements in the browser only, so server rendering is safe. The Solid wrapper creates its element while rendering, so render it on the client only (in SolidStart, with clientOnly).

React ​

sh
npm i @sigport/react
tsx
import { SignIn, SignInButton, useCreateSigport, useSigport, SigportProvider } from '@sigport/react';

export function Login() {
  return <SignIn appName="My app" exclude="okx" onSignIn={(account) => console.log(account.pubkey)} />;
}

// Share one session, and read it anywhere:
function App() {
  const sigport = useCreateSigport({ adapters: all() });
  return (
    <SigportProvider sigport={sigport}>
      <Header />
      <SignIn />
    </SigportProvider>
  );
}

function Header() {
  const { active } = useSigport();
  return active ? <span>{active.pubkey.slice(0, 8)}</span> : <SignInButton />;
}

Vue ​

sh
npm i @sigport/vue
vue
<script setup lang="ts">
import { SignIn, createAndProvideSigport, useSigport } from '@sigport/vue';
import { all } from '@sigport/core/all';

createAndProvideSigport({ adapters: all({ exclude: ['okx'] }) });
const state = useSigport();
</script>

<template>
  <p v-if="state.active">Signed in</p>
  <SignIn v-else app-name="My app" @signin="(account) => console.log(account.pubkey)" />
</template>

When Vue compiles templates, tell it the sigport- tags are custom elements:

ts
// vite.config.ts
vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.startsWith('sigport-') } } });

Svelte ​

sh
npm i @sigport/svelte
svelte
<script>
  import { SignIn, sigportStore } from '@sigport/svelte';
  import { createSigport } from '@sigport/core';
  import { all } from '@sigport/core/all';

  const sigport = createSigport({ adapters: all() });
  const session = sigportStore(sigport);
</script>

{#if $session.active}
  <p>Signed in as {$session.active.pubkey}</p>
{:else}
  <SignIn {sigport} appName="My app" onsignin={(account) => console.log(account)} />
{/if}

Solid ​

sh
npm i @sigport/solid
tsx
import { SignIn, createSigportSession, useSigport } from '@sigport/solid';
import { all } from '@sigport/core/all';

function App() {
  const sigport = createSigportSession({ adapters: all() });
  const state = useSigport(sigport);
  return <Show when={state().active} fallback={<SignIn sigport={sigport} appName="My app" />}>Signed in</Show>;
}

Angular ​

Angular uses the custom elements directly:

ts
// main.ts
import '@sigport/elements/define';
ts
@Component({
  selector: 'app-login',
  standalone: true,
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `<sigport-signin app-name="My app" (sigport-signin)="onSignIn($event)"></sigport-signin>`,
})
export class LoginComponent {
  onSignIn(event: Event) {
    const account = (event as CustomEvent).detail.account;
  }
}

Plain HTML, Astro, Lit, Qwik and the rest ​

Anything that renders HTML can use the elements:

html
<script type="module">import '@sigport/elements/define';</script>
<sigport-signin app-name="My app"></sigport-signin>

In Astro, put the import in a <script> tag (Astro bundles it for the browser), or in a client:only island.

MIT licensed.