npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sloikaxyz/remix-auth-siwe

v1.0.0

Published

Sign in with Ethereum and Passport

Downloads

2

Readme

MIT License

@sloikaxyz/remix-auth-siwe

A Remix Auth strategy to sign in with Ethereum

@sloikaxyz/remix-auth-siwe provides a remix-siwe authentication strategy for Sign in with Ethereum.

Strategy Name

siwe

Supported runtimes

| Runtime | Has Support | | ---------- | ----------- | | Node.js | ✅ | | Cloudflare | ✅ |

How to use

Set up the authenticator:

// app/services/auth.server.ts
import { Authenticator } from "remix-auth";
import { SiweStrategy } from "remix-auth-siwe";

import { sessionStorage } from "~/services/session.server";
import type { User } from "~/services/session.server";

// Create an instance of the authenticator, pass a generic with what
// strategies will return and will store in the session
export let authenticator = new Authenticator<User>(sessionStorage, {
  sessionKey: "sessionKey", // keep in sync
  sessionErrorKey: "sessionErrorKey", // keep in sync
});

authenticator.use(
  new SiweStrategy({ domain: "localhost:3000" }, async ({ message }) => {
    return await Promise.resolve({ address: message.address });
  }),
  "siwe"
);

Create an action to authenticate user:

export const action: ActionFunction = async ({ request, context }) => {
  await authenticator.authenticate("siwe", request, {
    successRedirect: "/",
    failureRedirect: "/login",
    context, // optional
  });
};

From your login entry point send message and signature as formData:

   import { useSubmit } from '@remix-run/react';
   import { SiweMessage } from 'siwe';


   export default function Screen() {
      const submit = useSubmit();

      function authenticate = useCallback(() => {
         // create siwe message
         const message = await new SiweMessage({ siweMessageOptions });
         // sign siwe message
         const signature = await signer.signMessage(message);

         const formData = new FormData();
         formData.append('message', message);
         formData.append('signature', signature);
         submit(formData, {
            action: {YOUR_LOGIN_ACTION},
            method: 'post',
            replace: true,
         });
      }, [submit])

      return <button onClick={authenticate}>Sign In</button>;
   }

You can check if the user is authenticated with authenticator.isAuthenticated and redirect to the dashboard if it is, or to login if it's not

export let loader: LoaderFunction = async ({ request }) => {
  // If the user is already authenticated redirect to /dashboard
  // otherwise redirect to /login
  return await authenticator.isAuthenticated(request, {
    successRedirect: "/dashboard",
    failureRedirect: "/login",
  });
};

You can get user object from authenticator.isAuthenticated:

let user = await authenticator.isAuthenticated(request, {
  failureRedirect: "/login",
});

Installation

Install with npm or yarn:

  npm install @sloikaxyz/remix-auth-siwe siwe@^2.0.5 ethers@^5.6.8
  # or
  yarn add @sloikaxyz/remix-auth-siwe siwe@^2.0.5 ethers@^5.6.8