Comment on page
Implementing the UserAuthorization Module
This section installs SSX as a dependency and implements Sign-In with Ethereum
In this step, we will see how to connect SSX with your application and use the UserAuthorization module to identify your user. In this quickstart, we will show how to authenticate your user on both the client and server.
To start, you need to install SSX on both your frontend and backend:
To use the SSX library on the backend, you must install
@spruceid/ssx-server
. Furthermore, we must create the routes required by the authorization module (nonce, sign in, and sign out) for our Next app. To add those, use the following commands:npm i @spruceid/ssx-server
You can create the folders and files by yourself or by running the bash command below:
mkdir app/api \
app/api/ssx-nonce \
app/api/ssx-login \
app/api/ssx-logout
touch .env.local \
app/api/_ssx.ts \
app/api/ssx-nonce/route.ts \
app/api/ssx-login/route.ts \
app/api/ssx-logout/route.ts
Then, add an environment variable into the
my-app/.env.local
file:SSX_SIGNING_KEY=anythingyouwanthere
Add a helper file to our code so that we don't have to instantiate a new SSX Server object directly every time. Add the following to
my-app/app/api/_ssx.ts
file:import { SSXServer } from "@spruceid/ssx-server";
const ssx = new SSXServer({
signingKey: process.env.SSX_SIGNING_KEY,
});