Docs

Migrate from Auth0.js to the Auth0 Single Page App SDK

In this article, you’ll see how to migrate your single page app (SPA) from auth0.js to auth0-spa-js. Listed below are scenarios using auth0.js and the equivalent auth0-spa-js code.

Functionality that cannot be migrated

Not all auth0.js functionality can be directly migrated to auth0-spa-js. Scenarios that cannot be directly migrated include:

Authentication Parameters are not modified anymore

Auth0.js converts custom parameters you set from camelCase to snake_case internally. For example, if you set deviceType: 'offline', auth0.js actually sends device_type: 'offline' to the server.

When using auth0-spa-js, custom parameters are not converted from camelCase to snake_case. It will relay whatever parameter you send to the authorization server.

Create the client

auth0.js

auth0-spa-js

Redirect to the Universal Login Page

auth0.js

auth0-spa-js

Parse the hash after the redirect

auth0.js

auth0-spa-js

Get the user information

auth0.js

The userInfo() function makes a call to the /userinfo endpoint and returns the user profile.

auth0-spa-js

Unlike auth0.js, the Auth0 SPA SDK does not call to the /userinfo endpoint for the user profile. Instead Auth0Client.getUser() returns user information from the decoded id_token.

Open the Universal Login Page in a popup

auth0.js

auth0-spa-js

Refresh tokens

auth0.js

auth0-spa-js

The Auth0 SPA SDK handles token refresh for you. Every time you call getTokenSilently, you'll either get a valid token or an error if there's no session at Auth0.

Get a token for a different audience or with more scopes

auth0.js

auth0-spa-js

The Auth0 SPA SDK handles token refresh for you. Every time you call getTokenSilently, you'll either get a valid token or an error if there's no session at Auth0.

Use getTokenWithPopup to open a popup and allow the user to consent to the new API: