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 🙏

© 2026 – Pkg Stats / Ryan Hefner

wp-auth

v1.0.7

Published

Authenticate users through node using WordPress cookies

Downloads

525

Readme

WP Auth (node-wp-authenticator)

npm license

A Node.js package to authenticate users using WordPress cookies.

Installation

Install via npm:

npm install wp-auth

Usage

1. Initialization

Initialize the authenticator with your WordPress database and keys.

const wp_auth = require('wp-auth').create({
    wpurl: 'http://my-blog.example',
    logged_in_key: 'LOGGED_IN_KEY from wp-config.php',
    logged_in_salt: 'LOGGED_IN_SALT from wp-config.php',
    mysql_host: 'localhost',
    mysql_user: 'root',
    mysql_pass: 'password',
    mysql_port: 3306, // Optional, defaults to 3306
    mysql_db: 'wordpress_db',
    wp_table_prefix: 'wp_', // Optional, defaults to 'wp_'
    skipAuthentication: false, // Optional, defaults to false
    debug: false, // Optional, defaults to false
    maxRetries: 5, // Optional, defaults to 5
    cacheTimeout: 300000 // Optional, defaults to 5 minutes (in ms)
});

Configuration Options

| Option | Type | Description | | :--- | :--- | :--- | | wpurl | String | The URL of your WordPress site. | | logged_in_key | String | The LOGGED_IN_KEY constant from your wp-config.php. | | logged_in_salt | String | The LOGGED_IN_SALT constant from your wp-config.php. | | mysql_host | String | MySQL database host. | | mysql_user | String | MySQL database username. | | mysql_pass | String | MySQL database password. | | mysql_db | String | MySQL database name. | | mysql_port | Number | MySQL port (default: 3306). | | wp_table_prefix | String | WordPress table prefix (default: wp_). | | skipAuthentication | Boolean | If true, bypasses hash checking and trusts the cookie ID (use with caution, mostly for testing). | | debug | Boolean | If true, enables verbose console logging. | | maxRetries | Number | Number of connection retries if MySQL connection fails. | | cacheTimeout | Number | Time in milliseconds to cache meta values and authentication checks (default: 300000 ms / 5 mins). |


2. Check Authentication

Verify if a user is logged in based on the request's cookies.

wp_auth.checkAuth(req).on('auth', function(auth_is_valid, user_id) {
    if (auth_is_valid) {
        console.log(`User is logged in. ID: ${user_id}`);
    } else {
        console.log('User is not logged in.');
    }
});
  • req: The HTTP request object (must have headers.cookie).
  • auth_is_valid: true if logged in, false otherwise.
  • user_id: The WordPress User ID (or 0 if not logged in).

3. User Meta Operations

Get User Meta

Retrieve a specific meta value for a user.

wp_auth.getUserMeta(user_id, 'first_name', function(data) {
    console.log('First Name:', data); 
    // data is null if key/user doesn't exist
});

Get Multiple User Metas

Retrieve multiple meta values at once.

wp_auth.getUserMetas(user_id, ['first_name', 'last_name'], function(data) {
    console.log('User Data:', data);
    // Returns array: [{ first_name: 'John' }, { last_name: 'Doe' }]
});

Set User Meta

Update or create a meta value for a user.

wp_auth.setUserMeta(user_id, 'user_status', 'active');

Reverse User Meta Query

Find a user ID based on a specific meta key-value pair.

wp_auth.reverseUserMeta('nickname', 'SuperUser', function(id) {
    if (id) {
        console.log(`Found User ID: ${id}`);
    } else {
        console.log('No user found.');
    }
});

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.