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

@enthusiastic/supertokens-node-enhancers

v0.0.3

Published

A simple set of utilities used for making the `supertokens-node` package more compatible with SSR frameworks.

Downloads

3

Readme

SuperTokens Node Enhancers

A simple set of utilities used for making the supertokens-node package more compatible with SSR frameworks.

Philosophy: Why Custom SuperTokens Utilities?

Currently, the supertokens-node package really only works well in settings that support middleware, like express. However, a middleware-based approach is highly incompatible with the emerging SSR frameworks today. This package aims to bridge the gap between supertokens-node and various SSR frameworks by creating utilities that enable SuperTokens to be used in a flexible, more robust way. In fact, this approach is so flexible that it will enable you to get SuperTokens working with popular SSR frameworks like Svelte Kit and SolidStart.

The approach laid out here attempts to make SuperTokens more flexible by only requiring request headers as inputs (and occasionally the request method) and only returning response headers and cookies as outputs. This gives the end developer vastly greater options to choose from (especially in Svelte Kit and SolidStart).

The downside of this approach is that it requires knowledge of supertokens-node internals. However, the SuperTokens team plans to simplify their tools to mimic the flexibility pursued/attained by this package. This package is only a temporary stand-in until the team finishes this work. Until then, I will keep this package up-to-date so that everything works correctly.

For more details on why I chose the approach and object structures that I did, see the following:

  • ITenthusiasm/remix-supertokens#5

How It Works

The approach is simple: Whenever a SuperTokens function (e.g., Session.getSession) would require you to pass a request object, replace the request object with an instance of SuperTokensData.Input. You can pass any data that the function needs into the constructor of SuperTokensData.Input. (Usually this will only be the reqest headers. Occasionally, you might need the request method due to a limitation of the internals of supertokens-node.)

Similarly, whenever a SuperTokens function (e.g., Session.getSession) would require you to pass a response object, replace the response object with an instance of SuperTokensData.Output. When you're done calling all of the necessary SuperTokens functions/methods, the responseHeaders property of SuperTokensData.Output will be correctly updated with everything needed to make sure that the auth in your app behaves correctly. Just be sure to include these response headers (and cookies) in the final response that you send back to the client.

"I Don't Want to Have to Write Code..."

Although this approach requires slightly more effort (i.e., you can't rely on the more concise app.use(middleware()) and app.use(errorHandler()) to get SuperTokens working anymore), it gives you greater clarity into what your app is doing; and it gives you greater control to make sure your app is doing exactly what you want. More importantly, you will have to do this anyway if you aren't using something like a Node adapter for an SSR framework.

Disclaimer

WARNING: This implementation relies on knowledge of SuperTokens internals. Although it is unlikely that SuperTokens would alter the supertokens-node codebase in such a way that this code would break, the danger is still there. This is only intended to be a temporary solution until the SuperTokens team supports something like this approach natively in supertokens-node. Nonetheless, it's the best that we've got right now for various SSR frameworks. And I will keep this package up to date as best as I can until better alternatives appear.