diff --git a/package-lock.json b/package-lock.json index e41f816..116408e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,25 +1,22 @@ { "name": "@sikka/hajar", - "version": "1.1.68", + "version": "1.1.69", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@sikka/hajar", - "version": "1.1.68", + "version": "1.1.69", "license": "MIT", "dependencies": { "@firebase/app": "~0.9.22", "@firebase/auth": "~1.3.2", - "@graphql-tools/schema": "~10.0.0", "@rollup/plugin-json": "~6.0.1", "aws-sdk": "~2.1490.0", "base64-stream": "~1.0.0", "bcrypt": "~5.1.1", "date-fns": "~2.30.0", "dotenv": "~16.3.1", - "graphql": "~16.8.1", - "graphql-tag": "~2.12.6", "handlebars": "~4.7.7", "jsonwebtoken": "~9.0.2", "moment": "~2.29.4", @@ -2026,63 +2023,6 @@ "tslib": "^2.1.0" } }, - "node_modules/@graphql-tools/merge": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/@graphql-tools/merge/-/merge-9.0.3.tgz", - "integrity": "sha512-FeKv9lKLMwqDu0pQjPpF59GY3HReUkWXKsMIuMuJQOKh9BETu7zPEFUELvcw8w+lwZkl4ileJsHXC9+AnsT2Lw==", - "dependencies": { - "@graphql-tools/utils": "^10.0.13", - "tslib": "^2.4.0" - }, - "engines": { - "node": ">=16.0.0" - }, - "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" - } - }, - "node_modules/@graphql-tools/schema": { - "version": "10.0.3", - "resolved": "https://registry.npmjs.org/@graphql-tools/schema/-/schema-10.0.3.tgz", - "integrity": "sha512-p28Oh9EcOna6i0yLaCFOnkcBDQECVf3SCexT6ktb86QNj9idnkhI+tCxnwZDh58Qvjd2nURdkbevvoZkvxzCog==", - "dependencies": { - "@graphql-tools/merge": "^9.0.3", - "@graphql-tools/utils": "^10.0.13", - "tslib": "^2.4.0", - "value-or-promise": "^1.0.12" - }, - "engines": { - "node": ">=16.0.0" - }, - "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" - } - }, - "node_modules/@graphql-tools/utils": { - "version": "10.1.2", - "resolved": "https://registry.npmjs.org/@graphql-tools/utils/-/utils-10.1.2.tgz", - "integrity": "sha512-fX13CYsDnX4yifIyNdiN0cVygz/muvkreWWem6BBw130+ODbRRgfiVveL0NizCEnKXkpvdeTy9Bxvo9LIKlhrw==", - "dependencies": { - "@graphql-typed-document-node/core": "^3.1.1", - "cross-inspect": "1.0.0", - "dset": "^3.1.2", - "tslib": "^2.4.0" - }, - "engines": { - "node": ">=16.0.0" - }, - "peerDependencies": { - "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" - } - }, - "node_modules/@graphql-typed-document-node/core": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/@graphql-typed-document-node/core/-/core-3.2.0.tgz", - "integrity": "sha512-mB9oAsNCm9aM3/SOv4YtBMqZbYj10R7dkq8byBqxGY/ncFwhf2oQzMV+LCRlWoDSEBJ3COiR1yeDvMtsoOsuFQ==", - "peerDependencies": { - "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" - } - }, "node_modules/@humanwhocodes/config-array": { "version": "0.11.14", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.14.tgz", @@ -4665,17 +4605,6 @@ "yarn": ">=1" } }, - "node_modules/cross-inspect": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/cross-inspect/-/cross-inspect-1.0.0.tgz", - "integrity": "sha512-4PFfn4b5ZN6FMNGSZlyb7wUhuN8wvj8t/VQHZdM4JsDcruGJ8L2kf9zao98QIrBPFCpdk27qst/AGTl7pL3ypQ==", - "dependencies": { - "tslib": "^2.4.0" - }, - "engines": { - "node": ">=16.0.0" - } - }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -4910,14 +4839,6 @@ "url": "https://github.com/motdotla/dotenv?sponsor=1" } }, - "node_modules/dset": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/dset/-/dset-3.1.3.tgz", - "integrity": "sha512-20TuZZHCEZ2O71q9/+8BwKwZ0QtD9D8ObhrihJPr+vLLYlSuAU3/zL4cSlgbfeoGHTjCSJBa7NGcrF9/Bx/WJQ==", - "engines": { - "node": ">=4" - } - }, "node_modules/eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", @@ -5887,28 +5808,6 @@ "integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==", "dev": true }, - "node_modules/graphql": { - "version": "16.8.1", - "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.8.1.tgz", - "integrity": "sha512-59LZHPdGZVh695Ud9lRzPBVTtlX9ZCV150Er2W43ro37wVof0ctenSaskPPjN7lVTIN8mSZt8PHUNKZuNQUuxw==", - "engines": { - "node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0" - } - }, - "node_modules/graphql-tag": { - "version": "2.12.6", - "resolved": "https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.12.6.tgz", - "integrity": "sha512-FdSNcu2QQcWnM2VNvSCCDCVS5PpPqpzgFT8+GXzqJuoDd0CBncxCY278u4mhRO7tMgo2JjgJA5aZ+nWSQ/Z+xg==", - "dependencies": { - "tslib": "^2.1.0" - }, - "engines": { - "node": ">=10" - }, - "peerDependencies": { - "graphql": "^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0" - } - }, "node_modules/handlebars": { "version": "4.7.8", "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.8.tgz", @@ -11167,14 +11066,6 @@ "spdx-expression-parse": "^3.0.0" } }, - "node_modules/value-or-promise": { - "version": "1.0.12", - "resolved": "https://registry.npmjs.org/value-or-promise/-/value-or-promise-1.0.12.tgz", - "integrity": "sha512-Z6Uz+TYwEqE7ZN50gwn+1LCVo9ZVrpxRPOhOLnncYkY1ZzOYtrX8Fwf/rFktZ8R5mJms6EZf5TqNOMeZmnPq9Q==", - "engines": { - "node": ">=12" - } - }, "node_modules/walker": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/walker/-/walker-1.0.8.tgz", diff --git a/package.json b/package.json index 287d849..091f21f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@sikka/hajar", - "version": "1.1.68", + "version": "1.1.69", "description": "Toolkit to create SaaS applications", "author": "Sikka Software (http://sikka.io)", "license": "MIT", @@ -63,15 +63,12 @@ "dependencies": { "@firebase/app": "~0.9.22", "@firebase/auth": "~1.3.2", - "@graphql-tools/schema": "~10.0.0", "@rollup/plugin-json": "~6.0.1", "aws-sdk": "~2.1490.0", "base64-stream": "~1.0.0", "bcrypt": "~5.1.1", "date-fns": "~2.30.0", "dotenv": "~16.3.1", - "graphql": "~16.8.1", - "graphql-tag": "~2.12.6", "handlebars": "~4.7.7", "jsonwebtoken": "~9.0.2", "moment": "~2.29.4", diff --git a/test/index.spec.js b/test/index.spec.js index e208e91..fdb15c2 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -1,8 +1,8 @@ -/* import { version as _version } from "../www/src/@sikka/hajar/index"; - */ +import { version as _version } from "../www/src/@sikka/hajar/index"; + import { version } from "../package.json"; describe("Hajar.src.js", () => { it("should get the library's version", () => { - expect(["1.1.68-beta", "1.1.68"]).toContain(version); + expect(["1.1.69-beta", "1.1.69"]).toContain(version); }); }); diff --git a/www/src/@sikka/hajar/core/auth/index.js b/www/src/@sikka/hajar/core/auth/index.js index d597dc5..46e909d 100644 --- a/www/src/@sikka/hajar/core/auth/index.js +++ b/www/src/@sikka/hajar/core/auth/index.js @@ -1,7 +1,8 @@ import { compare } from "bcrypt"; import { sign } from "jsonwebtoken"; -async function login(models, config, email, password) { +async function login(config, email, password) { + const { models } = config.mongoose; const user = await models.User.findOne({ email }); if (!user) { throw new Error("User not found"); @@ -12,8 +13,14 @@ async function login(models, config, email, password) { throw new Error("Invalid password"); } - const token = sign({ _id: user._id }, config.secret); - return token; + const accessToken = sign({ _id: user._id }, config.secret, { + expiresIn: "7d", + }); + const refreshToken = sign({ userId: user._id }, config.refreshTokenSecret, { + expiresIn: "7d", + }); + + return { accessToken, refreshToken }; } export { login }; diff --git a/www/src/@sikka/hajar/core/index.js b/www/src/@sikka/hajar/core/index.js index 19cc153..7f6f161 100644 --- a/www/src/@sikka/hajar/core/index.js +++ b/www/src/@sikka/hajar/core/index.js @@ -2,7 +2,6 @@ import { login } from "./auth/index.js"; class Hajar { constructor() { - this.models = null; this.config = null; this.initialized = false; this.auth = { @@ -10,22 +9,17 @@ class Hajar { if (!this.initialized) { throw new Error("Hajar is not initialized"); } - return login(this.models, this.config, email, password); + return login(this.config, email, password); }.bind(this), }; } - initHajar(jwtSecret, mongooseInstance, userModel, adminModel, clientModel) { + initHajar(jwtSecret, refreshToken, mongooseInstance) { if (this.initialized) { throw new Error("Hajar is already initialized"); } - - this.models = { - User: userModel, - Admin: adminModel, - Client: clientModel, - }; this.config = { secret: jwtSecret, + refreshTokenSecret: refreshToken, mongoose: mongooseInstance, }; this.initialized = true;