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

kemal_jwt_auth_companion

v1.2.2

Published

A client-side companion to make autheticating with a Kemal server a breeze.

Downloads

13

Readme

Kemal JWT Auth Companion

A companion to the Kemal JWT Auth shard for the Crystal language, this library makes authenticating a user as simple as login(username, password).

Installation and build

# To install
yarn add kemal-jwt-auth-companion
# To build a version to use from the browser
yarn build

That's about it. After that you can set your script tag's src to the output file in the build dir within the project dir, import it, or require it.

This project uses Webpack and Babel to target browsers, but can be used by node scripts as well.

See the server library for deployment of a server, including a working example. See deployment.md for a fully integrated walkthrough for all boilerplate needed to use this with React.js, although there's no reason it can't be used in other frameworks or just vanilla JS.

Usage

import auth from 'kemal-jwt-auth-companion'
// OR
const auth = require('kemal-jwt-auth-companion')
// OR include the script tag with the built library
const { login, authFetch } = auth('https://my.host/', '/api/sign_in')

login('my-username', 'my password').then(() => {
  authFetch(`${HOSTNAME}/api/some/endpoint`)
    .then(res => {
      if( res.ok ) return res.json()
      else return { errors: ['request to /api/some/endpoint failed'] } })
    .then(data => {
      if( data.errors && Array.isArray(data.errors))
        return data.errors.forEach(console.error)
      doSomethingWith(data) })
})

Also available is the authXHR function which provides a new XHR with authentication set up already.

Testing

Currently testing is done manually via the example at index.html. Since the library is so small, this seems reasonable to me, but a PR or discussion around automated testing solutions would be welcome.

The manual testing process is as follows:

  1. clone this repo, as well as the server-side library.
  2. install the dependencies -- Crystal, Node, and NPM/Yarn
  3. Run the example from the server library (from within the server library repository, run crystal run example/example.cr), or run your own authenticated Kemal server on port 3000.
  4. From this project's directory, run npm start.
  5. Visit http://localhost:8080/index.html and open the dev console (F12). A JWT should be displayed, and requests made to https://localhost:8080/api will be authenticated and proxied to the server library example server.