sol-auth 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/auth.controller.d.ts +2 -0
- package/dist/auth/auth.controller.d.ts.map +1 -0
- package/dist/auth/auth.controller.js +3 -0
- package/dist/auth/auth.controller.js.map +1 -0
- package/dist/auth/auth.service.d.ts +2 -0
- package/dist/auth/auth.service.d.ts.map +1 -0
- package/dist/auth/auth.service.js +47 -0
- package/dist/auth/auth.service.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/package.json +29 -0
- package/src/auth/auth.service.ts +83 -0
- package/src/index.ts +2 -0
- package/tsconfig.json +46 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.controller.d.ts","sourceRoot":"","sources":["../../src/auth/auth.controller.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.controller.js","sourceRoot":"","sources":["../../src/auth/auth.controller.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../src/auth/auth.service.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const bcrypt = require("bcrypt");
|
|
4
|
+
const jwt = require("jsonwebtoken");
|
|
5
|
+
async function signIn({ username, email, password, salt }) {
|
|
6
|
+
if (!((username || email) && password)) {
|
|
7
|
+
return Error("Missing Field");
|
|
8
|
+
}
|
|
9
|
+
if (email) {
|
|
10
|
+
if (!email.includes("@")) {
|
|
11
|
+
return Error("Email should contains @");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
if (password.length != 8) {
|
|
15
|
+
return Error("Password length should be 8");
|
|
16
|
+
}
|
|
17
|
+
if (!/^(?=.*[A-Z])/.test(password)) {
|
|
18
|
+
return Error("Password must contain at least one Uppercase letter");
|
|
19
|
+
}
|
|
20
|
+
else if (!/(?=.*[a-z])/.test(password)) {
|
|
21
|
+
return Error("Password must contain at least one Lowercase letter");
|
|
22
|
+
}
|
|
23
|
+
else if (!/(?=.*\d)/.test(password)) {
|
|
24
|
+
return Error("Password must contain at least one digit");
|
|
25
|
+
}
|
|
26
|
+
else if (!/(?=.*[@$!%*?&])/.test(password)) {
|
|
27
|
+
return Error('Password must contain at least one symbol');
|
|
28
|
+
}
|
|
29
|
+
const hashPassword = await bcrypt.hash(password, salt);
|
|
30
|
+
return { username, email, hashPassword };
|
|
31
|
+
}
|
|
32
|
+
async function logIn({ username, email, password, hashPassword, payload, secret, expiresIn }) {
|
|
33
|
+
if (!((username || email) && password)) {
|
|
34
|
+
return Error("Missing Field");
|
|
35
|
+
}
|
|
36
|
+
const isPasswordValid = await bcrypt.compare(password, hashPassword);
|
|
37
|
+
if (!isPasswordValid) {
|
|
38
|
+
return Error("Password is not valid");
|
|
39
|
+
}
|
|
40
|
+
let token = undefined;
|
|
41
|
+
if (payload || secret) {
|
|
42
|
+
token = jwt.sign({ payload }, secret, { expiresIn: expiresIn || "2hr" });
|
|
43
|
+
}
|
|
44
|
+
return { username, email, password: isPasswordValid, token };
|
|
45
|
+
}
|
|
46
|
+
module.exports = { signIn, logIn };
|
|
47
|
+
//# sourceMappingURL=auth.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../../src/auth/auth.service.ts"],"names":[],"mappings":";;AAAA,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;AAChC,MAAM,GAAG,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;AAoBnC,KAAK,UAAU,MAAM,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAa;IA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AQ,IAAI,KAAK,CAAC,IAAI,QAAQ,CAAC,EAAE,CAAC;QACrC,OAAO,KAAK,CAAC,eAAe,CAAC,CAAA;IACjC,CAAC;IAED,MAAM,eAAe,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;IAEpE,IAAI,CAAC,eAAe,EAAE,CAAC;QACnB,OAAO,KAAK,CAAC,uBAAuB,CAAC,CAAA;IACzC,CAAC;IAED,IAAI,KAAK,GAAwB,SAAS,CAAA;IAE1C,IAAI,OAAO,IAAI,MAAM,EAAE,CAAC;QACpB,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,SAAS,IAAI,KAAK,EAAE,CAAC,CAAA;IAC5E,CAAC;IAID,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,KAAK,EAAE,CAAA;AAChE,CAAC;AAID,MAAM,CAAC,OAAO,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AACA,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sol-auth",
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "ts-node src/index.ts",
|
|
9
|
+
"build": "tsc"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [],
|
|
12
|
+
"author": "",
|
|
13
|
+
"license": "ISC",
|
|
14
|
+
"type": "commonjs",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"bcrypt": "^6.0.0",
|
|
17
|
+
"dotenv": "^17.2.3",
|
|
18
|
+
"express": "^5.1.0",
|
|
19
|
+
"jsonwebtoken": "^9.0.2"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/bcrypt": "^6.0.0",
|
|
23
|
+
"@types/express": "^5.0.5",
|
|
24
|
+
"@types/jsonwebtoken": "^9.0.10",
|
|
25
|
+
"@types/node": "^24.10.0",
|
|
26
|
+
"ts-node": "^10.9.2",
|
|
27
|
+
"typescript": "^5.9.3"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const bcrypt = require("bcrypt")
|
|
2
|
+
const jwt = require("jsonwebtoken")
|
|
3
|
+
|
|
4
|
+
interface signInput {
|
|
5
|
+
username?: string,
|
|
6
|
+
email?: string,
|
|
7
|
+
password: string,
|
|
8
|
+
salt: Number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface logInput {
|
|
12
|
+
username?: string,
|
|
13
|
+
email?: string,
|
|
14
|
+
password?: string,
|
|
15
|
+
hashPassword: string,
|
|
16
|
+
secret: string,
|
|
17
|
+
payload: any,
|
|
18
|
+
expiresIn?: any
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
async function signIn({ username, email, password, salt }: signInput) {
|
|
23
|
+
|
|
24
|
+
if (!((username || email) && password)) {
|
|
25
|
+
return Error("Missing Field")
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
if (email) {
|
|
32
|
+
if (!email.includes("@")) {
|
|
33
|
+
return Error("Email should contains @")
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
if (password.length != 8) {
|
|
39
|
+
return Error("Password length should be 8")
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!/^(?=.*[A-Z])/.test(password)) {
|
|
43
|
+
return Error("Password must contain at least one Uppercase letter")
|
|
44
|
+
} else if (!/(?=.*[a-z])/.test(password)) {
|
|
45
|
+
return Error("Password must contain at least one Lowercase letter")
|
|
46
|
+
} else if (!/(?=.*\d)/.test(password)) {
|
|
47
|
+
return Error("Password must contain at least one digit")
|
|
48
|
+
} else if (!/(?=.*[@$!%*?&])/.test(password)) {
|
|
49
|
+
return Error('Password must contain at least one symbol')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const hashPassword = await bcrypt.hash(password, salt)
|
|
53
|
+
|
|
54
|
+
return { username, email, hashPassword }
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function logIn({ username, email, password, hashPassword, payload, secret, expiresIn }: logInput) {
|
|
60
|
+
if (!((username || email) && password)) {
|
|
61
|
+
return Error("Missing Field")
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const isPasswordValid = await bcrypt.compare(password, hashPassword)
|
|
65
|
+
|
|
66
|
+
if (!isPasswordValid) {
|
|
67
|
+
return Error("Password is not valid")
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let token : string | undefined = undefined
|
|
71
|
+
|
|
72
|
+
if (payload || secret) {
|
|
73
|
+
token = jwt.sign({ payload }, secret, { expiresIn: expiresIn || "2hr" })
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
return { username, email, password: isPasswordValid, token }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
module.exports = { signIn, logIn }
|
package/src/index.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Visit https://aka.ms/tsconfig to read more about this file
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
// File Layout
|
|
5
|
+
"rootDir": "./src",
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
|
|
8
|
+
// Environment Settings
|
|
9
|
+
// See also https://aka.ms/tsconfig/module
|
|
10
|
+
"module": "commonjs",
|
|
11
|
+
"target": "es2020",
|
|
12
|
+
// "types": [],
|
|
13
|
+
"esModuleInterop":true,
|
|
14
|
+
"moduleResolution": "node",
|
|
15
|
+
// For nodejs:
|
|
16
|
+
// "lib": ["esnext"],
|
|
17
|
+
"types": ["node"],
|
|
18
|
+
// and npm install -D @types/node
|
|
19
|
+
|
|
20
|
+
// Other Outputs
|
|
21
|
+
"sourceMap": true,
|
|
22
|
+
"declaration": true,
|
|
23
|
+
"declarationMap": true,
|
|
24
|
+
|
|
25
|
+
// Stricter Typechecking Options
|
|
26
|
+
"noUncheckedIndexedAccess": true,
|
|
27
|
+
"exactOptionalPropertyTypes": true,
|
|
28
|
+
|
|
29
|
+
// Style Options
|
|
30
|
+
// "noImplicitReturns": true,
|
|
31
|
+
// "noImplicitOverride": true,
|
|
32
|
+
// "noUnusedLocals": true,
|
|
33
|
+
// "noUnusedParameters": true,
|
|
34
|
+
// "noFallthroughCasesInSwitch": true,
|
|
35
|
+
// "noPropertyAccessFromIndexSignature": true,
|
|
36
|
+
|
|
37
|
+
// Recommended Options
|
|
38
|
+
"strict": true,
|
|
39
|
+
"jsx": "react-jsx",
|
|
40
|
+
"verbatimModuleSyntax": true,
|
|
41
|
+
"isolatedModules": true,
|
|
42
|
+
"noUncheckedSideEffectImports": true,
|
|
43
|
+
"moduleDetection": "force",
|
|
44
|
+
"skipLibCheck": true,
|
|
45
|
+
}
|
|
46
|
+
}
|