/Replit-Identity

Primary LanguageJavaScriptMIT LicenseMIT

Replit Identity

Supports TypeScript

Create and verify Replit Identity tokens.

NPM Version NPM Install Size NPM Downloads

const { create, verify } = require('replit-identity');

const audience = 'target-repl-id';
const token = await create(audience);

const info = await verify(token, audience);
console.log(info);

Installation

npm install replit-identity

Important: This package can only be used within a Replit environment.

API

The replit-identity module exports the following functions:

create

Creates a new identity token.

  • param: audience (string): The target audience for the token.
  • returns: A Promise resolving to the string token, or null on error.

verify

Verifies an existing identity token.

  • param: token (string): The token to verify.
  • param: audience (string): The audience to verify against.
  • returns: A Promise resolving to an object containing token information, or null if the token is invalid.

Example return value:

const info = {
  slug: "repl-name", 
  replId: "unique-repl-id",
  audience: "target-repl-id", 
  username: "jane_doe" ,
  userId: 12345,
  runtime: {
    // Based on Replit environment:
    interactive: {
      cluster: 'example-cluster',
      subcluster: 'example-subcluster'
    },
    // Or:
    hosting: {
      cluster: 'example-cluster',
      subcluster: 'example-subcluster'
    },
    // Or (if in deployment):
    deployment: true,
  }
}