very-express 0.5.20 → 0.5.22
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/.eslintrc.json +0 -0
- package/.gitattributes +0 -0
- package/.github/workflows/npm-start.yml +0 -0
- package/LICENSE +0 -0
- package/README.md +62 -62
- package/dist/index.js +331 -352
- package/dist/templates/_projectSettings/env +22 -22
- package/dist/templates/_projectSettings/package.json +49 -49
- package/dist/templates/_roles/_RoleFactory.ts +2 -2
- package/dist/templates/_routes/oauth/OAuthRouteFactory.ts +1 -1
- package/dist/templates/_services/auth/JWTService.ts +23 -23
- package/dist/templates/jsonSchema/User.json +85 -85
- package/dist/templates/root/README.md +11 -10
- package/dist/templates/root/public/css/style.css +7 -7
- package/dist/templates/root/public/js/login.js +58 -58
- package/dist/templates/root/public/js/logincallback.js +18 -18
- package/dist/templates/root/public/js/mytokens.js +10 -10
- package/dist/templates/root/public/js/refreshtokens.js +22 -22
- package/docs/ForeignKey.md +0 -0
- package/docs/appGenerated/auth.md +0 -0
- package/docs/developmentNote.md +0 -0
- package/docs/releaseNote/v0-5-0.md +0 -0
- package/docs/roadMap/released.md +0 -0
- package/docs/roadMap/v0-6-0.md +0 -0
- package/docs/roadMap/v0-7-0.md +0 -0
- package/docs/vexJsonSchema.md +0 -0
- package/package.json +51 -51
- package/scripts/build.js +0 -0
- package/scripts/copyTsTemplates.js +0 -0
- package/scripts/merge.js +0 -0
- package/tsconfig.json +121 -121
- package/vex.config.json +36 -36
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
APP_HOST=http://localhost
|
|
2
|
-
APP_PORT=3000
|
|
3
|
-
MONGODB_URI=mongodb://localhost:27017/veryExpressDB
|
|
4
|
-
|
|
5
|
-
LOGIN_SUCCESS_REDIRECT_PATH=/logincallback
|
|
6
|
-
LOGIN_FAILED_REDIRECT_PATH=/logincallback
|
|
7
|
-
|
|
8
|
-
# OAUTH
|
|
9
|
-
OAUTH_GOOGLE_CLIENTID=
|
|
10
|
-
OAUTH_GOOGLE_CLIENTSECRET=
|
|
11
|
-
OAUTH_GITHUB_CLIENTID=
|
|
12
|
-
OAUTH_GITHUB_CLIENTSECRET=
|
|
13
|
-
# OAUTH_MICROSOFT_CLIENTID=
|
|
14
|
-
# OAUTH_MICROSOFT_CLIENTSECRET=
|
|
15
|
-
# OAUTH_APPLE_CLIENTID=
|
|
16
|
-
# OAUTH_APPLE_CLIENTSECRET=
|
|
17
|
-
|
|
18
|
-
# JWT token
|
|
19
|
-
ACCESS_TOKEN_EXPIRE_TIME='5m'
|
|
20
|
-
REFRESH_TOKEN_EXPIRE_TIME='15m'
|
|
21
|
-
SESSION_COOKIE_SECRET='my-session-cookie-secret'
|
|
22
|
-
JWT_ALGORITHM='HS256'
|
|
1
|
+
APP_HOST=http://localhost
|
|
2
|
+
APP_PORT=3000
|
|
3
|
+
MONGODB_URI=mongodb://localhost:27017/veryExpressDB
|
|
4
|
+
|
|
5
|
+
LOGIN_SUCCESS_REDIRECT_PATH=/logincallback
|
|
6
|
+
LOGIN_FAILED_REDIRECT_PATH=/logincallback
|
|
7
|
+
|
|
8
|
+
# OAUTH
|
|
9
|
+
OAUTH_GOOGLE_CLIENTID=
|
|
10
|
+
OAUTH_GOOGLE_CLIENTSECRET=
|
|
11
|
+
OAUTH_GITHUB_CLIENTID=
|
|
12
|
+
OAUTH_GITHUB_CLIENTSECRET=
|
|
13
|
+
# OAUTH_MICROSOFT_CLIENTID=
|
|
14
|
+
# OAUTH_MICROSOFT_CLIENTSECRET=
|
|
15
|
+
# OAUTH_APPLE_CLIENTID=
|
|
16
|
+
# OAUTH_APPLE_CLIENTSECRET=
|
|
17
|
+
|
|
18
|
+
# JWT token
|
|
19
|
+
ACCESS_TOKEN_EXPIRE_TIME='5m'
|
|
20
|
+
REFRESH_TOKEN_EXPIRE_TIME='15m'
|
|
21
|
+
SESSION_COOKIE_SECRET='my-session-cookie-secret'
|
|
22
|
+
JWT_ALGORITHM='HS256'
|
|
23
23
|
JWT_SECRET0='my-secret-key0'
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
{
|
|
2
|
-
"main": "index.js",
|
|
3
|
-
"scripts": {
|
|
4
|
-
"build": "tsc -p . && node scripts/build.js",
|
|
5
|
-
"start": "node dist/server.js",
|
|
6
|
-
"dev": "nodemon --watch src --exec ts-node src/server.ts",
|
|
7
|
-
"docker-build": "docker build -t very-express .",
|
|
8
|
-
"docker-start": "docker run -p 3000:3000 very-express"
|
|
9
|
-
},
|
|
10
|
-
"dependencies": {
|
|
11
|
-
"cookie": "^0.6.0",
|
|
12
|
-
"cookie-parser": "^1.4.6",
|
|
13
|
-
"dotenv": "^16.4.4",
|
|
14
|
-
"express": "^4.18.2",
|
|
15
|
-
"express-validator": "^7.0.1",
|
|
16
|
-
"helmet": "^7.1.0",
|
|
17
|
-
"js-yaml": "^4.1.0",
|
|
18
|
-
"jsonwebtoken": "^9.0.2",
|
|
19
|
-
"mongo-ts-querystring": "^1.0.4",
|
|
20
|
-
"mongodb": "^5.6.0",
|
|
21
|
-
"mongoose": "^7.4.0",
|
|
22
|
-
"passport": "^0.7.0",
|
|
23
|
-
"passport-google-oauth20": "^2.0.0",
|
|
24
|
-
"passport-github": "^1.1.0",
|
|
25
|
-
"passport-jwt": "^4.0.1",
|
|
26
|
-
"swagger-ui-express": "^5.0.0"
|
|
27
|
-
},
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"@types/cookie-parser": "^1.4.7",
|
|
30
|
-
"@types/jsonwebtoken": "^9.0.7",
|
|
31
|
-
"@types/crypto-js": "^4.1.2",
|
|
32
|
-
"@types/dotenv": "^8.2.0",
|
|
33
|
-
"@types/express": "^4.17.17",
|
|
34
|
-
"@types/express-validator": "^3.0.0",
|
|
35
|
-
"@types/js-yaml": "^4.0.9",
|
|
36
|
-
"@types/mongodb": "^4.0.7",
|
|
37
|
-
"@types/ms": "^2.1.0",
|
|
38
|
-
"@types/node": "^20.4.2",
|
|
39
|
-
"@types/passport": "^1.0.16",
|
|
40
|
-
"@types/passport-google-oauth20": "^2.0.14",
|
|
41
|
-
"@types/passport-github": "^1.1.12",
|
|
42
|
-
"@types/sequelize": "^4.28.15",
|
|
43
|
-
"@types/swagger-ui-express": "^4.1.6",
|
|
44
|
-
"@types/ws": "^8.5.5",
|
|
45
|
-
"nodemon": "^2.0.22",
|
|
46
|
-
"strip-json-comments": "^5.0.1",
|
|
47
|
-
"ts-node": "^10.9.1",
|
|
48
|
-
"typescript": "^5.1.6"
|
|
49
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"main": "index.js",
|
|
3
|
+
"scripts": {
|
|
4
|
+
"build": "tsc -p . && node scripts/build.js",
|
|
5
|
+
"start": "node dist/server.js",
|
|
6
|
+
"dev": "nodemon --watch src --exec ts-node src/server.ts",
|
|
7
|
+
"docker-build": "docker build -t very-express .",
|
|
8
|
+
"docker-start": "docker run -p 3000:3000 very-express"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"cookie": "^0.6.0",
|
|
12
|
+
"cookie-parser": "^1.4.6",
|
|
13
|
+
"dotenv": "^16.4.4",
|
|
14
|
+
"express": "^4.18.2",
|
|
15
|
+
"express-validator": "^7.0.1",
|
|
16
|
+
"helmet": "^7.1.0",
|
|
17
|
+
"js-yaml": "^4.1.0",
|
|
18
|
+
"jsonwebtoken": "^9.0.2",
|
|
19
|
+
"mongo-ts-querystring": "^1.0.4",
|
|
20
|
+
"mongodb": "^5.6.0",
|
|
21
|
+
"mongoose": "^7.4.0",
|
|
22
|
+
"passport": "^0.7.0",
|
|
23
|
+
"passport-google-oauth20": "^2.0.0",
|
|
24
|
+
"passport-github": "^1.1.0",
|
|
25
|
+
"passport-jwt": "^4.0.1",
|
|
26
|
+
"swagger-ui-express": "^5.0.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/cookie-parser": "^1.4.7",
|
|
30
|
+
"@types/jsonwebtoken": "^9.0.7",
|
|
31
|
+
"@types/crypto-js": "^4.1.2",
|
|
32
|
+
"@types/dotenv": "^8.2.0",
|
|
33
|
+
"@types/express": "^4.17.17",
|
|
34
|
+
"@types/express-validator": "^3.0.0",
|
|
35
|
+
"@types/js-yaml": "^4.0.9",
|
|
36
|
+
"@types/mongodb": "^4.0.7",
|
|
37
|
+
"@types/ms": "^2.1.0",
|
|
38
|
+
"@types/node": "^20.4.2",
|
|
39
|
+
"@types/passport": "^1.0.16",
|
|
40
|
+
"@types/passport-google-oauth20": "^2.0.14",
|
|
41
|
+
"@types/passport-github": "^1.1.12",
|
|
42
|
+
"@types/sequelize": "^4.28.15",
|
|
43
|
+
"@types/swagger-ui-express": "^4.1.6",
|
|
44
|
+
"@types/ws": "^8.5.5",
|
|
45
|
+
"nodemon": "^2.0.22",
|
|
46
|
+
"strip-json-comments": "^5.0.1",
|
|
47
|
+
"ts-node": "^10.9.1",
|
|
48
|
+
"typescript": "^5.1.6"
|
|
49
|
+
}
|
|
50
50
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// {{headerComment}}
|
|
2
|
-
export type accessAction = "create" | "read" | "update" | "delete";
|
|
3
|
-
export const accessActionArr: accessAction[] = ["create", "read", "update", "delete"];
|
|
2
|
+
export type accessAction = "create" | "read" | "search" | "update" | "delete";
|
|
3
|
+
export const accessActionArr: accessAction[] = ["create", "read", "search", "update", "delete"];
|
|
4
4
|
|
|
5
5
|
export interface accessControl< T = accessAction > {
|
|
6
6
|
[key:string]: T[]
|
|
@@ -72,7 +72,7 @@ export default class OAuthRouteFactory {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
// return appAuthCode to client
|
|
75
|
-
const redirectUrl = await this.JWTService.assignTokens(req.user as User
|
|
75
|
+
const redirectUrl = await this.JWTService.assignTokens(req.user as User);
|
|
76
76
|
return res.redirect(redirectUrl);
|
|
77
77
|
|
|
78
78
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import jwt from "jsonwebtoken";
|
|
3
3
|
import ms from "ms";
|
|
4
4
|
import path from "path";
|
|
5
|
-
import express from "express";
|
|
5
|
+
// import express, { CookieOptions } from "express";
|
|
6
6
|
|
|
7
7
|
import JWTKeyStore from "./JWTKeyStore.gen";
|
|
8
8
|
import utils from "../../_utils";
|
|
@@ -56,40 +56,40 @@ export default class JWTService {
|
|
|
56
56
|
/**
|
|
57
57
|
* Process of login user, assign tokens and create session.
|
|
58
58
|
*/
|
|
59
|
-
public async assignTokens(user: User
|
|
59
|
+
public async assignTokens(user: User) {
|
|
60
60
|
if(!user._id) {
|
|
61
61
|
throw new VexResponseError(500, utils.response.code.err_db_data, "User Data Error, User._id missing.");
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
const accessToken = await this.generateAccessToken(user._id);
|
|
65
|
-
const refreshToken = await this.generateRefreshToken({ _id: user._id });
|
|
64
|
+
// const accessToken = await this.generateAccessToken(user._id);
|
|
65
|
+
// const refreshToken = await this.generateRefreshToken({ _id: user._id });
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
secure: true,
|
|
74
|
-
sameSite: "strict",
|
|
75
|
-
});
|
|
67
|
+
// const accessTokenOptions: CookieOptions = {
|
|
68
|
+
// maxAge: ms(process.env.ACCESS_TOKEN_EXPIRE_TIME as ms.StringValue),
|
|
69
|
+
// httpOnly: true,
|
|
70
|
+
// secure: true,
|
|
71
|
+
// sameSite: "strict",
|
|
72
|
+
// };
|
|
76
73
|
|
|
77
|
-
res.cookie("
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
74
|
+
// res.cookie("authorization", accessToken.token, accessTokenOptions);
|
|
75
|
+
// res.cookie("x-auth-index", accessToken.clientIndex, accessTokenOptions);
|
|
76
|
+
|
|
77
|
+
// res.cookie("vex-refresh-token", {
|
|
78
|
+
// refreshToken: refreshToken.token,
|
|
79
|
+
// refreshTokenIndex: refreshToken.clientIndex,
|
|
80
|
+
// }, {
|
|
81
|
+
// maxAge: ms(process.env.REFRESH_TOKEN_EXPIRE_TIME as ms.StringValue),
|
|
82
|
+
// httpOnly: true,
|
|
83
|
+
// secure: true,
|
|
84
|
+
// sameSite: "strict",
|
|
85
|
+
// });
|
|
86
86
|
|
|
87
87
|
const sessionCode = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
88
88
|
|
|
89
89
|
SessionModel.create({
|
|
90
90
|
sessionCode: sessionCode,
|
|
91
91
|
userId: user._id,
|
|
92
|
-
provider: "local",
|
|
92
|
+
// provider: "local",
|
|
93
93
|
expired: Date.now() + 5000
|
|
94
94
|
});
|
|
95
95
|
|
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
{
|
|
2
|
-
"type": "object",
|
|
3
|
-
"x-documentConfig": {
|
|
4
|
-
"methods": [
|
|
5
|
-
"get",
|
|
6
|
-
"getList",
|
|
7
|
-
"post",
|
|
8
|
-
"patch"
|
|
9
|
-
],
|
|
10
|
-
"documentName": "User"
|
|
11
|
-
},
|
|
12
|
-
"properties": {
|
|
13
|
-
"_id": {
|
|
14
|
-
"type": "string",
|
|
15
|
-
"x-format": "ObjectId",
|
|
16
|
-
"index": true
|
|
17
|
-
},
|
|
18
|
-
"authProfiles": {
|
|
19
|
-
"type": "array",
|
|
20
|
-
"items": {
|
|
21
|
-
"type": "object",
|
|
22
|
-
"properties": {
|
|
23
|
-
"provider": {
|
|
24
|
-
"type": "string",
|
|
25
|
-
"index": true
|
|
26
|
-
},
|
|
27
|
-
"authId": {
|
|
28
|
-
"type": "string",
|
|
29
|
-
"index": true
|
|
30
|
-
},
|
|
31
|
-
"username": {
|
|
32
|
-
"type": "string"
|
|
33
|
-
},
|
|
34
|
-
"password": {
|
|
35
|
-
"type": "string"
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
"required": []
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
"email": {
|
|
42
|
-
"type": "string",
|
|
43
|
-
"format": "email",
|
|
44
|
-
"index": true
|
|
45
|
-
},
|
|
46
|
-
"name": {
|
|
47
|
-
"type": "string",
|
|
48
|
-
"maxLength": 64,
|
|
49
|
-
"required": true
|
|
50
|
-
},
|
|
51
|
-
"active": {
|
|
52
|
-
"type": "boolean",
|
|
53
|
-
"default": true,
|
|
54
|
-
"required": true
|
|
55
|
-
},
|
|
56
|
-
"locale": {
|
|
57
|
-
"type": "string",
|
|
58
|
-
"maxLength": 8
|
|
59
|
-
},
|
|
60
|
-
"roles": {
|
|
61
|
-
"type": "array",
|
|
62
|
-
"x-vexData": "role",
|
|
63
|
-
"items": {
|
|
64
|
-
"type": "string",
|
|
65
|
-
"enum": [
|
|
66
|
-
"visitor",
|
|
67
|
-
"member",
|
|
68
|
-
"admin"
|
|
69
|
-
]
|
|
70
|
-
},
|
|
71
|
-
"default": [
|
|
72
|
-
"visitor"
|
|
73
|
-
]
|
|
74
|
-
},
|
|
75
|
-
"profileErrors": {
|
|
76
|
-
"type": "array",
|
|
77
|
-
"items": {
|
|
78
|
-
"type": "string"
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
"required": [
|
|
83
|
-
"name",
|
|
84
|
-
"active"
|
|
85
|
-
]
|
|
1
|
+
{
|
|
2
|
+
"type": "object",
|
|
3
|
+
"x-documentConfig": {
|
|
4
|
+
"methods": [
|
|
5
|
+
"get",
|
|
6
|
+
"getList",
|
|
7
|
+
"post",
|
|
8
|
+
"patch"
|
|
9
|
+
],
|
|
10
|
+
"documentName": "User"
|
|
11
|
+
},
|
|
12
|
+
"properties": {
|
|
13
|
+
"_id": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"x-format": "ObjectId",
|
|
16
|
+
"index": true
|
|
17
|
+
},
|
|
18
|
+
"authProfiles": {
|
|
19
|
+
"type": "array",
|
|
20
|
+
"items": {
|
|
21
|
+
"type": "object",
|
|
22
|
+
"properties": {
|
|
23
|
+
"provider": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"index": true
|
|
26
|
+
},
|
|
27
|
+
"authId": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
"index": true
|
|
30
|
+
},
|
|
31
|
+
"username": {
|
|
32
|
+
"type": "string"
|
|
33
|
+
},
|
|
34
|
+
"password": {
|
|
35
|
+
"type": "string"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"required": []
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"email": {
|
|
42
|
+
"type": "string",
|
|
43
|
+
"format": "email",
|
|
44
|
+
"index": true
|
|
45
|
+
},
|
|
46
|
+
"name": {
|
|
47
|
+
"type": "string",
|
|
48
|
+
"maxLength": 64,
|
|
49
|
+
"required": true
|
|
50
|
+
},
|
|
51
|
+
"active": {
|
|
52
|
+
"type": "boolean",
|
|
53
|
+
"default": true,
|
|
54
|
+
"required": true
|
|
55
|
+
},
|
|
56
|
+
"locale": {
|
|
57
|
+
"type": "string",
|
|
58
|
+
"maxLength": 8
|
|
59
|
+
},
|
|
60
|
+
"roles": {
|
|
61
|
+
"type": "array",
|
|
62
|
+
"x-vexData": "role",
|
|
63
|
+
"items": {
|
|
64
|
+
"type": "string",
|
|
65
|
+
"enum": [
|
|
66
|
+
"visitor",
|
|
67
|
+
"member",
|
|
68
|
+
"admin"
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
"default": [
|
|
72
|
+
"visitor"
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
"profileErrors": {
|
|
76
|
+
"type": "array",
|
|
77
|
+
"items": {
|
|
78
|
+
"type": "string"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"required": [
|
|
83
|
+
"name",
|
|
84
|
+
"active"
|
|
85
|
+
]
|
|
86
86
|
}
|
|
@@ -2,24 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
# Quick Start
|
|
5
|
+
1. install `very-express` from npm
|
|
6
|
+
`npm install -g very-express` or `npm update -g very-express`
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
[vex.config.json](./vex.config.json)
|
|
8
|
-
|
|
9
|
-
2. generate the app with your vex.config settings.
|
|
10
|
-
*Note : every db schema changes require to regenerate app.
|
|
8
|
+
2. check configuration file [vex.config.json](./vex.config.json) under project root directory and keep it updated (re-generate the app with very-express).
|
|
11
9
|
`vex`
|
|
12
|
-
|
|
10
|
+
|
|
11
|
+
3. we should have a express typescript app.
|
|
13
12
|
```
|
|
14
13
|
├── src/
|
|
15
|
-
│ └──
|
|
14
|
+
│ └── openapi
|
|
15
|
+
│ └── roles (role based access control settings)
|
|
16
|
+
│ └── system (very express generated app)
|
|
16
17
|
├── package.json
|
|
17
18
|
├── tsconfig.json
|
|
18
19
|
├── vex.config.json
|
|
19
20
|
├── .env
|
|
20
21
|
└── ...
|
|
21
22
|
```
|
|
22
|
-
|
|
23
|
+
|
|
23
24
|
4. start the generated express app.
|
|
24
25
|
```
|
|
25
26
|
npm i
|
|
@@ -32,7 +33,7 @@
|
|
|
32
33
|
npm run docker-build
|
|
33
34
|
npm run docker-start
|
|
34
35
|
```
|
|
36
|
+
|
|
35
37
|
# Resource
|
|
36
38
|
- [Documents](https://github.com/Justin26l/VeryExpress/blob/main/README.md)
|
|
37
|
-
|
|
38
|
-
- [Discord](https://discord.gg/PZGMzDp7)
|
|
39
|
+
- [VeryExpress Discord](https://discord.gg/PZGMzDp7)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
pre {
|
|
3
|
-
background-color: #f4f4f4;
|
|
4
|
-
padding: 20px;
|
|
5
|
-
overflow: auto;
|
|
6
|
-
border: 1px solid #ccc;
|
|
7
|
-
white-space: pre-wrap;
|
|
1
|
+
|
|
2
|
+
pre {
|
|
3
|
+
background-color: #f4f4f4;
|
|
4
|
+
padding: 20px;
|
|
5
|
+
overflow: auto;
|
|
6
|
+
border: 1px solid #ccc;
|
|
7
|
+
white-space: pre-wrap;
|
|
8
8
|
}
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
document.addEventListener("DOMContentLoaded", function() {
|
|
3
|
-
// add event listener to login button
|
|
4
|
-
document.querySelector("#localLoginBtn").addEventListener("click", function() {
|
|
5
|
-
// call api /auth/local
|
|
6
|
-
fetch("/auth/local", {
|
|
7
|
-
method: "POST",
|
|
8
|
-
headers: {
|
|
9
|
-
"Content-Type": "application/json"
|
|
10
|
-
},
|
|
11
|
-
body: JSON.stringify({
|
|
12
|
-
email: document.querySelector("#email").value,
|
|
13
|
-
password: document.querySelector("#password").value
|
|
14
|
-
})
|
|
15
|
-
})
|
|
16
|
-
.then(async (res) => {
|
|
17
|
-
if(res.status === 302) {
|
|
18
|
-
const data = await res.json();
|
|
19
|
-
if(data.result?.url){
|
|
20
|
-
window.location.href = data.result?.url;
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
alert("Login successful, but no redirect URL provided.");
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
const data = await res.json();
|
|
28
|
-
alert("Login failed: " + data.message);
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
.catch((err) => {
|
|
32
|
-
console.error("Error during login:", err);
|
|
33
|
-
alert("An error occurred during login. Please try again later.");
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
document.querySelector("#localRegisterBtn").addEventListener("click", function() {
|
|
38
|
-
// call api /auth/local
|
|
39
|
-
fetch("/auth/register", {
|
|
40
|
-
method: "POST",
|
|
41
|
-
headers: {
|
|
42
|
-
"Content-Type": "application/json"
|
|
43
|
-
},
|
|
44
|
-
body: JSON.stringify({
|
|
45
|
-
email: document.querySelector("#email").value,
|
|
46
|
-
password: document.querySelector("#password").value
|
|
47
|
-
})
|
|
48
|
-
})
|
|
49
|
-
.then(async (res) => {
|
|
50
|
-
if(res.status === 201) {
|
|
51
|
-
alert("Registration successful. You can now log in.");
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
.catch((err) => {
|
|
55
|
-
console.error("Error during registration:", err);
|
|
56
|
-
alert("An error occurred during registration. Please try again later.");
|
|
57
|
-
});
|
|
58
|
-
});
|
|
1
|
+
|
|
2
|
+
document.addEventListener("DOMContentLoaded", function() {
|
|
3
|
+
// add event listener to login button
|
|
4
|
+
document.querySelector("#localLoginBtn").addEventListener("click", function() {
|
|
5
|
+
// call api /auth/local
|
|
6
|
+
fetch("/auth/local", {
|
|
7
|
+
method: "POST",
|
|
8
|
+
headers: {
|
|
9
|
+
"Content-Type": "application/json"
|
|
10
|
+
},
|
|
11
|
+
body: JSON.stringify({
|
|
12
|
+
email: document.querySelector("#email").value,
|
|
13
|
+
password: document.querySelector("#password").value
|
|
14
|
+
})
|
|
15
|
+
})
|
|
16
|
+
.then(async (res) => {
|
|
17
|
+
if(res.status === 302) {
|
|
18
|
+
const data = await res.json();
|
|
19
|
+
if(data.result?.url){
|
|
20
|
+
window.location.href = data.result?.url;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
alert("Login successful, but no redirect URL provided.");
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const data = await res.json();
|
|
28
|
+
alert("Login failed: " + data.message);
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
.catch((err) => {
|
|
32
|
+
console.error("Error during login:", err);
|
|
33
|
+
alert("An error occurred during login. Please try again later.");
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
document.querySelector("#localRegisterBtn").addEventListener("click", function() {
|
|
38
|
+
// call api /auth/local
|
|
39
|
+
fetch("/auth/register", {
|
|
40
|
+
method: "POST",
|
|
41
|
+
headers: {
|
|
42
|
+
"Content-Type": "application/json"
|
|
43
|
+
},
|
|
44
|
+
body: JSON.stringify({
|
|
45
|
+
email: document.querySelector("#email").value,
|
|
46
|
+
password: document.querySelector("#password").value
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
.then(async (res) => {
|
|
50
|
+
if(res.status === 201) {
|
|
51
|
+
alert("Registration successful. You can now log in.");
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
.catch((err) => {
|
|
55
|
+
console.error("Error during registration:", err);
|
|
56
|
+
alert("An error occurred during registration. Please try again later.");
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
59
|
});
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
document.addEventListener("DOMContentLoaded", function() {
|
|
3
|
-
console.log('Exchange Tokens from /auth/token');
|
|
4
|
-
let sessionCode = new URLSearchParams(location.search).get('code');
|
|
5
|
-
fetch(
|
|
6
|
-
'/auth/token?code=' + sessionCode, {
|
|
7
|
-
method: 'POST'
|
|
8
|
-
}
|
|
9
|
-
)
|
|
10
|
-
.then((res) => res.text())
|
|
11
|
-
.then((data) => {
|
|
12
|
-
const jsonData = JSON.parse(data);
|
|
13
|
-
document.querySelector("#tokenData").innerHTML = JSON.stringify(jsonData, null, 2);
|
|
14
|
-
localStorage.setItem('accessToken', jsonData.result.accessToken);
|
|
15
|
-
localStorage.setItem('accessTokenIndex', jsonData.result.accessTokenIndex);
|
|
16
|
-
localStorage.setItem('refreshToken', jsonData.result.refreshToken);
|
|
17
|
-
localStorage.setItem('refreshTokenIndex', jsonData.result.refreshTokenIndex);
|
|
18
|
-
});
|
|
1
|
+
|
|
2
|
+
document.addEventListener("DOMContentLoaded", function() {
|
|
3
|
+
console.log('Exchange Tokens from /auth/token');
|
|
4
|
+
let sessionCode = new URLSearchParams(location.search).get('code');
|
|
5
|
+
fetch(
|
|
6
|
+
'/auth/token?code=' + sessionCode, {
|
|
7
|
+
method: 'POST'
|
|
8
|
+
}
|
|
9
|
+
)
|
|
10
|
+
.then((res) => res.text())
|
|
11
|
+
.then((data) => {
|
|
12
|
+
const jsonData = JSON.parse(data);
|
|
13
|
+
document.querySelector("#tokenData").innerHTML = JSON.stringify(jsonData, null, 2);
|
|
14
|
+
localStorage.setItem('accessToken', jsonData.result.accessToken);
|
|
15
|
+
localStorage.setItem('accessTokenIndex', jsonData.result.accessTokenIndex);
|
|
16
|
+
localStorage.setItem('refreshToken', jsonData.result.refreshToken);
|
|
17
|
+
localStorage.setItem('refreshTokenIndex', jsonData.result.refreshTokenIndex);
|
|
18
|
+
});
|
|
19
19
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
let jsonData = {};
|
|
2
|
-
|
|
3
|
-
document.addEventListener("DOMContentLoaded", function () {
|
|
4
|
-
jsonData = {
|
|
5
|
-
accessToken: localStorage.getItem("accessToken"),
|
|
6
|
-
accessTokenIndex: localStorage.getItem("accessTokenIndex"),
|
|
7
|
-
refreshToken: localStorage.getItem("refreshToken"),
|
|
8
|
-
refreshTokenIndex: localStorage.getItem("refreshTokenIndex"),
|
|
9
|
-
};
|
|
10
|
-
document.querySelector("#tokenData").innerHTML = JSON.stringify(jsonData, null, 2);
|
|
1
|
+
let jsonData = {};
|
|
2
|
+
|
|
3
|
+
document.addEventListener("DOMContentLoaded", function () {
|
|
4
|
+
jsonData = {
|
|
5
|
+
accessToken: localStorage.getItem("accessToken"),
|
|
6
|
+
accessTokenIndex: localStorage.getItem("accessTokenIndex"),
|
|
7
|
+
refreshToken: localStorage.getItem("refreshToken"),
|
|
8
|
+
refreshTokenIndex: localStorage.getItem("refreshTokenIndex"),
|
|
9
|
+
};
|
|
10
|
+
document.querySelector("#tokenData").innerHTML = JSON.stringify(jsonData, null, 2);
|
|
11
11
|
});
|