Skip to content

Commit

Permalink
Merge pull request #63 from sikka-software/feature/enhance-hajar-usab…
Browse files Browse the repository at this point in the history
…ility-js

Feature/enhance hajar usability js
  • Loading branch information
Mansourkira committed Mar 20, 2024
2 parents 88dbb3d + 356703c commit 624cfca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sikka/hajar",
"version": "1.1.74",
"version": "1.1.75",
"description": "Toolkit to create SaaS applications",
"author": "Sikka Software <contact@sikka.io> (http://sikka.io)",
"license": "MIT",
Expand Down
8 changes: 7 additions & 1 deletion www/src/@sikka/hajar/core/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ async function login(email, password, config) {
};
}

// @TODO: Add the ability to register a client in the same function
async function register(userDetails, config) {
try {
const { models } = config.mongoose;
Expand Down Expand Up @@ -93,7 +94,7 @@ async function register(userDetails, config) {

const newUser = await user.save();

const admin = new config.mongoose.models.Admin({
const admin = new models.Admin({
profile: newUser._id,
role: adminRole._id,
uid: newUser._id,
Expand All @@ -105,12 +106,17 @@ async function register(userDetails, config) {
const newAdmin = await admin.save();

const token = sign({ _id: newUser._id }, config.secret);
// i need to add the refresh token here
const refreshToken = sign({ _id: newUser._id }, config.refreshTokenSecret, {
expiresIn: "30d",
});

return {
success: true,
user: { ...newUser.toObject() },
admin: { ...newAdmin.toObject() },
token,
refreshToken,
};
} catch (error) {
console.error("Registration error:", error);
Expand Down

0 comments on commit 624cfca

Please sign in to comment.