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

wapplr-authentication

v1.0.72

Published

An authentication service for Wapplr

Downloads

193

Readme

Wapplr-authentication

This package is an authentication service for Wapplr.

//server.js
import wapplrAuthentication from "wapplr-authentication";
import wapplrServer from "wapplr";

const wapp = wapplrServer({config: {
        server: {
            database: {
                mongoConnectionString: "mongodb://localhost/wapplr",
            }
        },
        globals: {
            WAPP: "yourBuildHash",
            ROOT: __dirname
        }
    }
});

wapplrAuthentication({wapp});

const namePattern = /^.{1,30}$/;
const emailPattern = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
const passwordPattern = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,256}$/;

const user = await wapp.server.authentications.getAuthentication({
    name: "author",
    addIfThereIsNot: true,
    config: {
        cookieSecret: "yourHash",
        cookieOptions: {secure: "auto", signed: true, httpOnly: true, maxAge: 7 * 24 * 60 * 60 * 1000},
        cookieName: "wapplr.uid",
        
        mongoConnectionString: "mongodb://localhost/wapplr",

        modelName: "User",
        schemaFields: {
            name: {
                first: {
                    type: String,
                    wapplr: {
                        pattern: namePattern,
                        required: true
                    }
                },
                last: {
                    type: String,
                    wapplr: {
                        pattern: namePattern,
                        private: "author"
                    }
                }
            },
            email: {
                type: String,
                wapplr: {
                    pattern: emailPattern,
                    private: "author",
                    required: true
                }
            },
            emailConfirmed: {
                type: Boolean,
                default: false,
                wapplr: {
                    readOnly: true,
                    private: "author"
                }
            },
            password: {
                type: String,
                wapplr: {
                    pattern: passwordPattern,
                    disabled: true
                }
            },
            passwordRecoveryKey: {
                type: String,
                wapplr: { disabled: true }
            },
            emailConfirmationKey: {
                type: String,
                wapplr: { disabled: true }
            },
        },
        setSchemaMiddleware: function({schema}){},

        statuses: {
            featured: 120,
            approved: 100,
            requiredData: 50,
            created: 40,
            deleted: 30,
            banned: 20
        },
        statusField: "_status",
        requiredDataForStatus: {
            name: {
                first: { type: String }
            },
            email: { type: String },
            emailConfirmed: { type: Boolean, value: true },
        },

        admin: {
            email: "[email protected]", 
            password: Math.random().toString(36).slice(-8),
            name: {
                first: "Billy",
                last: "The Kid", 
            },
        },

        messages: {
            savePostDefaultFail: "Sorry, there was an issue save the entry, please try again",
            invalidData: "Invalid data",
            missingData: "Missing data",
            lowStatusLevel: "Your status level is too low to perform the operation",
            postNotFound: "User not found",
            accessDenied: "You do not have permission to perform that operation",

            signFail: "Sorry, there was an issue signing you in, please try again",

            missingEmail: "Missing email",
            invalidEmail: "Invalid email",
            incorrectEmail: "Incorrect email",
            usedEmail: "Email was already used",
            noChanges: "No changes",

            missingPassword: "Missing password",
            invalidPassword: "Invalid password",
            incorrectPassword: "Incorrect password",

            missingPasswordRecoveryKey: "Missing password recovery key",
            incorrectPasswordRecoveryKey: "Incorrect password recovery key",

            missingEmailConfirmationKey: "Missing email confirmation key",
            incorrectEmailConfirmationKey: "Incorrect email confirmation key",
            alreadyConfirmedEmail: "Your email address has already been confirmed",

            alreadyLoggedIn: "You are already logged in to this session",
            thereWasNoUser: "there was no user in the session",

            validationName: "Minimum 1 maximum 30 characters",
            validationEmail: "Invalid email format",
            validationPassword: "Min 8 characters both upper and lowercase",
        },
        
        labels: {
            firstName: "First name",
            lastName: "Last name",
            email: "Email",
            password: "Password",
            newPassword: "New password",
            emailConfirmationKey: "Email confirmation key"
        },

        resolvers: {
            getAll: function ({Model}) { 
                return {
                    extendResolver: "findMany",
                    args: null,
                    resolve: async function({input}) {
                        return await Model.find();
                    }
                }
            },
        }
    }
})

wapp.server.listen();
//client.js
import wapplrClient from "wapplr";
import wapplrAuthentication from "wapplr-authentication";

const wapp = wapplrClient({config: {
        globals: {
            WAPP: "yourBuildHash"
        }
    }
});

wapp.client.authentications.getAuthentication({
    name: "user",
    addIfThereIsNot: true
});

wapp.client.listen();

/*...*/
const send = wapp.requests.send;
const response = await send({requestName:"userGetAll"});
const users = response.userGetAll;

License

MIT