Skip to content

Commit f50b874

Browse files
feat: Add user details feature to dashboard recipe (#432)
* refactor: Refactor dashboard api functions to be strongly typed (#411) * Refactor dashboard api functions to be strongly typed * Refactor dashboard api functions to be strongly typed * Refactor dashboard api functions to be strongly typed * Refactor dashboard api functions to be strongly typed * Refactor dashboard api functions to be strongly typed * feat: Add GET APIs for user details changed to the dashboard (#412) * Add get user API to dashboard recipe * Add email verify get api to dashboard recipe * Add user metadata get api to dashboard recipe * Add user sessions get api to dashboard recipe * Refactor based on PR comments * feat: Add Delete and Put APIs for user details to the dashboard recipe (#416) * Add user delete API * Add email verify put API to dashboard recipe * Add usermetadata put API to dashboard recipe * Add user password put API to dashboard recipe * Add user put API to dashboard recipe * Refactor based on PR comments * Ensure that meta data is a valid object in metadata put API * feat: Add post APIs for user details to dashboard recipe (#417) * Add user delete API * Add email verify put API to dashboard recipe * Add usermetadata put API to dashboard recipe * Add user password put API to dashboard recipe * Add user put API to dashboard recipe * Add user email verify token post API to dashboard recipe * Add user sessions post API to dashboard recipe * Fix * Fix * Update package version and dashboard version * Update package version and Changelog Co-authored-by: Rishabh Poddar <[email protected]>
1 parent 394f19c commit f50b874

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2935
-65
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [unreleased]
99

10+
## [12.1.0] - 2022-11-17
11+
12+
### Added:
13+
14+
- Adds APIs for user details to the dashboard recipe
15+
16+
### Changed:
17+
18+
- Updates dashboard version to 0.2
19+
1020
## [12.0.6] - 2022-11-09
1121

1222
### Fixes

lib/build/recipe/dashboard/api/apiKeyProtector.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ function apiKeyProtector(apiImplementation, options, apiFunction) {
5858
utils_2.sendUnauthorisedAccess(options.res);
5959
return true;
6060
}
61-
return yield apiFunction(apiImplementation, options);
61+
const response = yield apiFunction(apiImplementation, options);
62+
options.res.sendJSONResponse(response);
63+
return true;
6264
});
6365
}
6466
exports.default = apiKeyProtector;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @ts-nocheck
2+
import { APIInterface, APIOptions } from "../../types";
3+
declare type Response = {
4+
status: "OK";
5+
};
6+
export declare const userDelete: (_: APIInterface, options: APIOptions) => Promise<Response>;
7+
export {};
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"use strict";
2+
var __awaiter =
3+
(this && this.__awaiter) ||
4+
function (thisArg, _arguments, P, generator) {
5+
function adopt(value) {
6+
return value instanceof P
7+
? value
8+
: new P(function (resolve) {
9+
resolve(value);
10+
});
11+
}
12+
return new (P || (P = Promise))(function (resolve, reject) {
13+
function fulfilled(value) {
14+
try {
15+
step(generator.next(value));
16+
} catch (e) {
17+
reject(e);
18+
}
19+
}
20+
function rejected(value) {
21+
try {
22+
step(generator["throw"](value));
23+
} catch (e) {
24+
reject(e);
25+
}
26+
}
27+
function step(result) {
28+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
29+
}
30+
step((generator = generator.apply(thisArg, _arguments || [])).next());
31+
});
32+
};
33+
Object.defineProperty(exports, "__esModule", { value: true });
34+
const supertokens_1 = require("../../../../supertokens");
35+
const error_1 = require("../../../../error");
36+
exports.userDelete = (_, options) =>
37+
__awaiter(void 0, void 0, void 0, function* () {
38+
const userId = options.req.getKeyValueFromQuery("userId");
39+
if (userId === undefined) {
40+
throw new error_1.default({
41+
message: "Missing required parameter 'userId'",
42+
type: error_1.default.BAD_INPUT_ERROR,
43+
});
44+
}
45+
yield supertokens_1.default.getInstanceOrThrowError().deleteUser({
46+
userId,
47+
});
48+
return {
49+
status: "OK",
50+
};
51+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// @ts-nocheck
2+
import { APIFunction } from "../../types";
3+
export declare const userEmailverifyGet: APIFunction;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"use strict";
2+
var __awaiter =
3+
(this && this.__awaiter) ||
4+
function (thisArg, _arguments, P, generator) {
5+
function adopt(value) {
6+
return value instanceof P
7+
? value
8+
: new P(function (resolve) {
9+
resolve(value);
10+
});
11+
}
12+
return new (P || (P = Promise))(function (resolve, reject) {
13+
function fulfilled(value) {
14+
try {
15+
step(generator.next(value));
16+
} catch (e) {
17+
reject(e);
18+
}
19+
}
20+
function rejected(value) {
21+
try {
22+
step(generator["throw"](value));
23+
} catch (e) {
24+
reject(e);
25+
}
26+
}
27+
function step(result) {
28+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
29+
}
30+
step((generator = generator.apply(thisArg, _arguments || [])).next());
31+
});
32+
};
33+
Object.defineProperty(exports, "__esModule", { value: true });
34+
const error_1 = require("../../../../error");
35+
const recipe_1 = require("../../../emailverification/recipe");
36+
const emailverification_1 = require("../../../emailverification");
37+
exports.userEmailverifyGet = (_, options) =>
38+
__awaiter(void 0, void 0, void 0, function* () {
39+
const req = options.req;
40+
const userId = req.getKeyValueFromQuery("userId");
41+
if (userId === undefined) {
42+
throw new error_1.default({
43+
message: "Missing required parameter 'userId'",
44+
type: error_1.default.BAD_INPUT_ERROR,
45+
});
46+
}
47+
try {
48+
recipe_1.default.getInstanceOrThrowError();
49+
} catch (e) {
50+
return {
51+
status: "FEATURE_NOT_ENABLED_ERROR",
52+
};
53+
}
54+
const response = yield emailverification_1.default.isEmailVerified(userId);
55+
return {
56+
status: "OK",
57+
isVerified: response,
58+
};
59+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @ts-nocheck
2+
import { APIInterface, APIOptions } from "../../types";
3+
declare type Response = {
4+
status: "OK";
5+
};
6+
export declare const userEmailVerifyPut: (_: APIInterface, options: APIOptions) => Promise<Response>;
7+
export {};
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"use strict";
2+
var __awaiter =
3+
(this && this.__awaiter) ||
4+
function (thisArg, _arguments, P, generator) {
5+
function adopt(value) {
6+
return value instanceof P
7+
? value
8+
: new P(function (resolve) {
9+
resolve(value);
10+
});
11+
}
12+
return new (P || (P = Promise))(function (resolve, reject) {
13+
function fulfilled(value) {
14+
try {
15+
step(generator.next(value));
16+
} catch (e) {
17+
reject(e);
18+
}
19+
}
20+
function rejected(value) {
21+
try {
22+
step(generator["throw"](value));
23+
} catch (e) {
24+
reject(e);
25+
}
26+
}
27+
function step(result) {
28+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
29+
}
30+
step((generator = generator.apply(thisArg, _arguments || [])).next());
31+
});
32+
};
33+
Object.defineProperty(exports, "__esModule", { value: true });
34+
const error_1 = require("../../../../error");
35+
const emailverification_1 = require("../../../emailverification");
36+
exports.userEmailVerifyPut = (_, options) =>
37+
__awaiter(void 0, void 0, void 0, function* () {
38+
const requestBody = yield options.req.getJSONBody();
39+
const userId = requestBody.userId;
40+
const verified = requestBody.verified;
41+
if (userId === undefined || typeof userId !== "string") {
42+
throw new error_1.default({
43+
message: "Required parameter 'userId' is missing or has an invalid type",
44+
type: error_1.default.BAD_INPUT_ERROR,
45+
});
46+
}
47+
if (verified === undefined || typeof verified !== "boolean") {
48+
throw new error_1.default({
49+
message: "Required parameter 'verified' is missing or has an invalid type",
50+
type: error_1.default.BAD_INPUT_ERROR,
51+
});
52+
}
53+
if (verified) {
54+
const tokenResponse = yield emailverification_1.default.createEmailVerificationToken(userId);
55+
if (tokenResponse.status === "EMAIL_ALREADY_VERIFIED_ERROR") {
56+
return {
57+
status: "OK",
58+
};
59+
}
60+
const verifyResponse = yield emailverification_1.default.verifyEmailUsingToken(tokenResponse.token);
61+
if (verifyResponse.status === "EMAIL_VERIFICATION_INVALID_TOKEN_ERROR") {
62+
// This should never happen because we consume the token immediately after creating it
63+
throw new Error("Should not come here");
64+
}
65+
} else {
66+
yield emailverification_1.default.unverifyEmail(userId);
67+
}
68+
return {
69+
status: "OK",
70+
};
71+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @ts-nocheck
2+
import { APIInterface, APIOptions } from "../../types";
3+
declare type Response = {
4+
status: "OK" | "EMAIL_ALREADY_VERIFIED_ERROR";
5+
};
6+
export declare const userEmailVerifyTokenPost: (_: APIInterface, options: APIOptions) => Promise<Response>;
7+
export {};
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
"use strict";
2+
var __awaiter =
3+
(this && this.__awaiter) ||
4+
function (thisArg, _arguments, P, generator) {
5+
function adopt(value) {
6+
return value instanceof P
7+
? value
8+
: new P(function (resolve) {
9+
resolve(value);
10+
});
11+
}
12+
return new (P || (P = Promise))(function (resolve, reject) {
13+
function fulfilled(value) {
14+
try {
15+
step(generator.next(value));
16+
} catch (e) {
17+
reject(e);
18+
}
19+
}
20+
function rejected(value) {
21+
try {
22+
step(generator["throw"](value));
23+
} catch (e) {
24+
reject(e);
25+
}
26+
}
27+
function step(result) {
28+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
29+
}
30+
step((generator = generator.apply(thisArg, _arguments || [])).next());
31+
});
32+
};
33+
Object.defineProperty(exports, "__esModule", { value: true });
34+
const error_1 = require("../../../../error");
35+
const emailverification_1 = require("../../../emailverification");
36+
const recipe_1 = require("../../../emailverification/recipe");
37+
const utils_1 = require("../../../emailverification/utils");
38+
exports.userEmailVerifyTokenPost = (_, options) =>
39+
__awaiter(void 0, void 0, void 0, function* () {
40+
const requestBody = yield options.req.getJSONBody();
41+
const userId = requestBody.userId;
42+
if (userId === undefined || typeof userId !== "string") {
43+
throw new error_1.default({
44+
message: "Required parameter 'userId' is missing or has an invalid type",
45+
type: error_1.default.BAD_INPUT_ERROR,
46+
});
47+
}
48+
let emailResponse = yield recipe_1.default.getInstanceOrThrowError().getEmailForUserId(userId, {});
49+
if (emailResponse.status !== "OK") {
50+
throw new Error("Should never come here");
51+
}
52+
let emailVerificationToken = yield emailverification_1.default.createEmailVerificationToken(userId);
53+
if (emailVerificationToken.status === "EMAIL_ALREADY_VERIFIED_ERROR") {
54+
return {
55+
status: "EMAIL_ALREADY_VERIFIED_ERROR",
56+
};
57+
}
58+
let emailVerifyLink = utils_1.getEmailVerifyLink({
59+
appInfo: options.appInfo,
60+
token: emailVerificationToken.token,
61+
recipeId: recipe_1.default.RECIPE_ID,
62+
});
63+
yield emailverification_1.default.sendEmail({
64+
type: "EMAIL_VERIFICATION",
65+
user: {
66+
id: userId,
67+
email: emailResponse.email,
68+
},
69+
emailVerifyLink,
70+
});
71+
return {
72+
status: "OK",
73+
};
74+
});

0 commit comments

Comments
 (0)