Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
netlify-identity-widget
Advanced tools
A component used to authenticate with Netlify's Identity service. Live demo
For a lower level library to the underlying GoTrue
API, see
gotrue-js.
Netlify’s Identity service is a plug-and-play microservice for handling site functionalities like signups, logins, password recovery, user metadata, and roles. You can use it from single page apps instead of rolling your own, and integrate with any service that understands JSON Web Tokens (JWTs).
Learn more about this service from this blog post.
Simply include the widget on your site, and things like invites, confirmation codes, etc, will start working.
You can add controls for the widget with HTML:
<!DOCTYPE html>
<html>
<head>
<title>A static website</title>
<!-- include the widget -->
<script type="text/javascript" src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>
</head>
<body>
<!-- Add a menu:
Log in / Sign up - when the user is not logged in
Username / Log out - when the user is logged in
-->
<div data-netlify-identity-menu></div>
<!-- Add a simpler button:
Simple button that will open the modal.
-->
<div data-netlify-identity-button>Login with Netlify Identity</div>
</body>
</html>
The widget will automatically attach itself to the window object as
window.netlifyIdentity
.
You can use this global object like this:
// open the modal
netlifyIdentity.open();
// Get the current user:
const user = netlifyIdentity.currentUser();
// Bind to events
netlifyIdentity.on("init", user => console.log(user));
netlifyIdentity.on("login", user => console.log(user));
netlifyIdentity.on("logout", () => console.log("Logged out"));
netlifyIdentity.on("error", err => console.error("Logged out"));
netlifyIdentity.on("open", () => console.log("Widget opened"));
netlifyIdentity.on("close", () => console.log("Widget closed"));
// Close the modal
netlifyIdentity.close();
// Logout the user
netlifyIdentity.logout();
The v1
in the above URL is not pinned to the major version of the module API,
and will only reflect breaking changes in the markup API.
Netlify Identity Widget also has a module api:
yarn add netlify-identity-widget
Import or require as usual:
const netlifyIdentity = require("netlify-identity-widget");
netlifyIdentity.init({
container: "#netlify-modal" // defaults to document.body,
});
netlifyIdentity.open(); // open the modal
netlifyIdentity.open("login"); // open the modal to the login tab
netlifyIdentity.open("signup"); // open the modal to the signup tab
netlifyIdentity.on("init", user => console.log(user));
netlifyIdentity.on("login", login => console.log(user));
netlifyIdentity.on("logout", () => console.log("Logged out"));
netlifyIdentity.on("error", err => console.error("Logged out"));
netlifyIdentity.on("open", () => console.log("Widget opened"));
netlifyIdentity.on("close", () => console.log("Widget closed"));
// Close the modal
netlifyIdentity.close();
// Logout the user
netlifyIdentity.logout();
// Access the underlying gotrue instance.
// Note that doing things directly through gotrue brings a risk of getting out of
// sync between your state and the widgets state.
netlifyIdentity.gotrue;
netlifyIdentity.init([opts])
You can pass an optional opts
object to configure the widget when using the
module api. Options include:
{
container: "#some-query-selector"; // container to attach to
APIUrl: "https://www.example.com/.netlify/functions/identity"; // Absolute url to endpoint. ONLY USE IN SPECIAL CASES!
}
Generally avoid setting the APIUrl
. You should only set this when your app is
served from a domain that differs from where the identity endpoint is served.
This is common for Cordova or Electron apps where you host from localhost or a
file.
When using the widget on localhost, it will prompt for your Netlify SiteURL the first time it is opened. Entering the siteURL populates the browser's localStorage.
This allows the widget to know which instance of Netlify Identity it should communicate with with zero configuration.
E.g. If your Netlify site is served from the olddvdscreensaver.com
domain
name, enter the following when prompted by the widget when in development mode:
https://olddvdscreensaver.com
localStorage.removeItem("netlifySiteURL");
example
for how to integrate this widget with a react app.FAQs
Netlify Identity widget for easy integration
The npm package netlify-identity-widget receives a total of 6,732 weekly downloads. As such, netlify-identity-widget popularity was classified as popular.
We found that netlify-identity-widget demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 23 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.