Not using React? Skip to the next section to learn how to use the SDK within any JavaScript or TypeScript app.

Install the SDK

npm i @gopasswordless/sdk

Initialise the SDK

import {
  GoPasswordlessContextProvider,
  GoPasswordlessWidgetComponent
} from "@gopasswordless/sdk";

const App = () => {
  return (
    <GoPasswordlessContextProvider
      settings={{
        appId: "YOUR_APP_ID",
        appName: "YOUR_APP_NAME",
        appLogo: "YOUR_APP_LOGO",
        primaryColour: "YOUR_APP_PRIMARY_COLOUR",
        theme: "light"
      }}
    >
      <GoPasswordlessWidgetComponent />
    <GoPasswordlessContextProvider />
  );
};

The above code initialises the SDK inside a React app and displays the GoPasswordlessWidgetComponent, which will handle the entire lifecycle of signing users up and loging them in.

You can use the hooks provided to access the user’s authentication token:

import { useGoPasswordlessContext } from '@gopasswordless/sdk';

...

const { token } = useGoPasswordlessContext();

Validate the token

You can validate the token server side using the validate function:

import { validate, TokenClaims } from "@gopasswordless/sdk";

let tokenClaims: TokenClaims;

try {
  tokenClaims = await validate("YOUR_APP_ID", token);
} catch (error) {
  console.log("validate throws if the token signature is invalid");
}