npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

authalert

v1.0.0

Published

AuthAlert instantly identifies new devices accessing user accounts and sends alerts via API, email, or webhook to enhance security and build trust.

Downloads

19

Readme

AuthAlert

Features

AuthAlert instantly identifies new devices accessing user accounts and sends alerts via API, email, or webhook, enhancing security and building trust. This package is designed to be used with JavaScript frontends such as React, Vue.js, Angular, and others.

  • Detect new devices used by your users
  • Respond to your frontend to trigger MFA only for new devices
  • Send email alerts to your users via Mailgun
  • Trigger webhooks to automate processes in your systems
  • Simple to implement and scale

Installation

To install the package, use the following command:

npm install authalert

Using the API

The API can be used as a Promise or an async function.

Async Function Example

import AuthAlertAPI from 'authalert';

const projectId = "your_project_ID";

const result = await AuthAlertAPI(projectId, {
  user_id: user.id,
  email: user.email,
  first_name: user.first_name,
  last_name: user.last_name
});

console.log(result);

Promise Example

import AuthAlertAPI from 'authalert';

const projectId = "your_project_ID";

AuthAlertAPI(projectId, {
  user_id: user.id,
  email: user.email,
  first_name: user.first_name,
  last_name: user.last_name
}).then(res => {
  console.log(res);
}).catch(err => {
  console.error(err);
});

To obtain your_project_ID, visit AuthAlert and create a project. The API supports the following input variables to populate user data:

| Name | Example | Description | Required | | --- | --- | --- | --- | | user_id | "ac5c7322" | A unique ID to identify the user. | Required | | email | "[email protected]" | The user's email address, used for sending alert emails. | Optional | | first_name | "John" | The user's first name, used in alert emails. | Optional | | last_name | "Smith" | The user's last name, used in alert emails. | Optional |

Authentication

To use the AuthAlert API in your frontend, you must add the domain names of your websites or web apps to the authorized domain list. Unauthorized API requests will result in 403 errors. You can manage your authorized domains in the AuthAlert platform here.

API Response

When the API is successfully called, it checks whether the user is new to the system and if the device is new to the user. The API then responds in the following format:

{
  "new_user": false,
  "new_device": true
}

To use the API for triggering MFA, redirect users to the MFA route when "new_device" is true. This approach triggers MFA only when users authenticate on new devices. You can also combine this with a "remember me" checkbox to give users the option to skip MFA on specific devices.

Mailgun Integration

The Mailgun integration allows you to enable email alerts without writing code when new devices are detected. To activate the integration, toggle the option in your AuthAlert project settings, then enter the domain, API key, sender email, subject line, and template name. You will need to create a template in your Mailgun account. The template can use the following variables:

| Name | Example | Description | | --- | --- | --- | | first_name | "John" | The user's first name. | | last_name | "Smith" | The user's last name. | | new_device_os | "Mac OS X" | The new device's operating system. | | new_device_os_version | "10" | The new device's operating system version. | | new_device_browser | "Firefox" | The new device's browser. | | new_device_browser_version | "128" | The new device's browser version. | | new_device_device_brand | "Apple" | The new device's brand. | | new_device_country | "AU" | The country code where the device is located. | | new_device_region | "NSW" | The state or province where the device is located. | | new_device_city | "Sydney" | The city or metro area where the device is located. | | new_device_detection_time | “2021-08-31 17:32:38 AEST” | The time when the device is first detected. |

Webhook Integration

The webhook integration enables programmatic interactions, such as integrating with CRM systems or communication channels beyond Mailgun. To enable the integration, toggle the option in your AuthAlert project settings, then enter the webhook URL and secret. When a new device is detected, AuthAlert will send the following JSON payload to the webhook URL:

{
  "user_id": "HZkj3L8we0gZjnHlrxziA53e1TH2",
  "email": "",
  "first_name": "",
  "last_name": "",
  "device_id": "6uex31zf1tx",
  "subscription_id": "q9enh4fcvjmPDDVR1mNT",
  "new_device": {
    "device_id": "6uex31zf1tx",
    "os": "Mac OS X",
    "os_version": "10",
    "browser": "Firefox",
    "browser_version": "128",
    "device_brand": "Apple",
    "device_model": "Mac",
    "device_family": "Mac",
    "country": "AU",
    "region": "NSW",
    "city": "Sydney",
    "city_lat_long": "-33.868820,151.209295",
    "detection_time": 1615819845,
    "timezone": "sydney/australia"
  }
}