thonatos / pV-Next

next version for implements.io

Home Page:https://next.implements.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ρV-Next

SSO - Auth provider powered by Ethereum & Next.js .

Sign-In with Ethereum.

使用以太坊对加签后在服务端验证签名并存储在 Session & Cookies 中,进而实现同级域名下的 SSO 认证。

use ethereum to sign your signature, verify by your backend app, then store it to session & cookies, then you can auth with SSO.

  • SSO Authentication with iron-session .
  • Mapping Roles by SPSR NFT (BSC Test Network) .

Authentication

share session fields.

export interface Credential {
  siwe?: any;
  roles?: string[];
}

after login with https://next.implements.io . we can get roles and wallet address by cookie-session under .implements.io with the fields.

// app/middleware/iron.ts
import { EggAppConfig, Context } from 'egg';
import { getIronSession } from 'iron-session';

export default (iron: EggAppConfig['iron']) => {
  return async (ctx: Context, next: () => Promise<any>) => {
    const options = iron.options;

    // @ts-ignore
    const ironSession = await getIronSession(ctx.req, ctx.res, options);

    // @ts-ignore
    const { credential } = ironSession;

    if (credential) {
      ctx.session.siwe = credential.siwe;
      ctx.session.roles = credential.roles;
    }

    await next();
  };
};

Prepare

  • install MetaMask and create an acount .

Develop

$ pnpm i
$ npm run dev
# or
$ yarn
$ yarn dev

Open http://localhost:3000 with your browser to see the result.

More

About

next version for implements.io

https://next.implements.io/


Languages

Language:TypeScript 98.0%Language:JavaScript 1.2%Language:Shell 0.3%Language:CSS 0.3%Language:Dockerfile 0.2%