@ionkit/authkit
v1.1.0
Published
AuthKit is a simple authentication system for Node.js using Sequelize.
Downloads
1
Readme
Ionkit / AuthKit
AuthKit is a simple authentication system for Node.js using Sequelize.
It is currently NOT STABLE, as it hasn't been fully tested. Use at own risk or wait until it gets stable.
Quick implementation of authentication using Sequelize
import authKit from "@ionkit/authkit";
import { Sequelize, Model, DataTypes } from "sequelize";
const sequelize = new Sequelize({
dialect: "sqlite",
storage: "/path/to/database.sqlite",
});
const { User, Group } = authKit({
sequelize,
});
sequelize.sync({ force: true }).then(async () => {
// Create a new user if none exists, otherwise return default. (id: 1)
const user = await User.findOrCreateDefault();
// Create a new group if none exists, otherwise return default. (gid: "OWNER")
const ownerGroup = await Group.findOrCreateDefault();
// Create a new group manually. (gid: "ADMIN", name: "Administrator")
const adminGroup = await Group.createGroup("ADMIN", "Administrator");
// Add user to both groups.
await user.addGroups([ownerGroup, adminGroup]);
// Setup finished.
console.log("User ready");
});