Skip to content

Commit cff50ce

Browse files
feat: Add email password login to the dashboard recipe (#490)
* Set authMode values as per the provided apiKey value * Removed empty key validation * Added further functionality * Added type to the APIinterface * Added case to handle the endpoint * Fixed types * Fixed the validation and sign in logic * Added type generics for predictive response * Added build files * Now returns the proper response * Added authmode to the normalised recipe * Kept the api key as optional * Made the api key optional * Added sign out endpoint * Removed try-catch block * Kept the signout method as post, enabled the function to be protected first * Add logic to initalise the dashboard recipe by default if the user has not already initialised it (#489) * Change package version and dashboard frontend version * Update CHANGELOG --------- Co-authored-by: AreebKhan619 <[email protected]>
1 parent 30ce11c commit cff50ce

35 files changed

+447
-76
lines changed

CHANGELOG.md

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

88
## [unreleased]
99

10+
## [13.1.0] - 2023-02-22
11+
12+
- Adds APIs and logic to the dashboard recipe to enable email password based login
13+
1014
## [13.0.2] - 2023-02-10
1115

1216
- Package version update for twilio to ^4.7.2 and verify-apple-id-token to ^3.0.1

coreDriverInterfaceSupported.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"_comment": "contains a list of core-driver interfaces branch names that this core supports",
3-
"versions": ["2.8", "2.9", "2.10", "2.11", "2.12", "2.13", "2.14", "2.15"]
3+
"versions": ["2.8", "2.9", "2.10", "2.11", "2.12", "2.13", "2.14", "2.15", "2.16", "2.17", "2.18"]
44
}

lib/build/querier.d.ts

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/build/querier.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ function getAPIImplementation() {
6666
new normalisedURLPath_1.default(bundleBasePathString).getAsStringDangerous();
6767
let connectionURI = "";
6868
const superTokensInstance = supertokens_1.default.getInstanceOrThrowError();
69+
const authMode = input.options.config.authMode;
6970
if (superTokensInstance.supertokens !== undefined) {
7071
connectionURI = superTokensInstance.supertokens.connectionURI;
7172
}
@@ -79,6 +80,7 @@ function getAPIImplementation() {
7980
.appendPath(new normalisedURLPath_1.default(constants_1.DASHBOARD_API))
8081
.getAsStringDangerous()}"
8182
window.connectionURI = "${connectionURI}"
83+
window.authMode = "${authMode}"
8284
</script>
8385
<script defer src="${bundleDomain}/static/js/bundle.js"></script></head>
8486
<link href="${bundleDomain}/static/css/main.css" rel="stylesheet" type="text/css">
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// @ts-nocheck
2+
import { APIInterface, APIOptions } from "../types";
3+
export default function signIn(_: APIInterface, options: APIOptions): Promise<boolean>;
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
"use strict";
2+
/* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved.
3+
*
4+
* This software is licensed under the Apache License, Version 2.0 (the
5+
* "License") as published by the Apache Software Foundation.
6+
*
7+
* You may not use this file except in compliance with the License. You may
8+
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
var __awaiter =
17+
(this && this.__awaiter) ||
18+
function (thisArg, _arguments, P, generator) {
19+
function adopt(value) {
20+
return value instanceof P
21+
? value
22+
: new P(function (resolve) {
23+
resolve(value);
24+
});
25+
}
26+
return new (P || (P = Promise))(function (resolve, reject) {
27+
function fulfilled(value) {
28+
try {
29+
step(generator.next(value));
30+
} catch (e) {
31+
reject(e);
32+
}
33+
}
34+
function rejected(value) {
35+
try {
36+
step(generator["throw"](value));
37+
} catch (e) {
38+
reject(e);
39+
}
40+
}
41+
function step(result) {
42+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
43+
}
44+
step((generator = generator.apply(thisArg, _arguments || [])).next());
45+
});
46+
};
47+
var __importDefault =
48+
(this && this.__importDefault) ||
49+
function (mod) {
50+
return mod && mod.__esModule ? mod : { default: mod };
51+
};
52+
Object.defineProperty(exports, "__esModule", { value: true });
53+
const utils_1 = require("../../../utils");
54+
const error_1 = __importDefault(require("../../../error"));
55+
const querier_1 = require("../../../querier");
56+
const normalisedURLPath_1 = __importDefault(require("../../../normalisedURLPath"));
57+
function signIn(_, options) {
58+
return __awaiter(this, void 0, void 0, function* () {
59+
const { email, password } = yield options.req.getJSONBody();
60+
if (email === undefined) {
61+
throw new error_1.default({
62+
message: "Missing required parameter 'email'",
63+
type: error_1.default.BAD_INPUT_ERROR,
64+
});
65+
}
66+
if (password === undefined) {
67+
throw new error_1.default({
68+
message: "Missing required parameter 'password'",
69+
type: error_1.default.BAD_INPUT_ERROR,
70+
});
71+
}
72+
let querier = querier_1.Querier.getNewInstanceOrThrowError(undefined);
73+
const signInResponse = yield querier.sendPostRequest(
74+
new normalisedURLPath_1.default("/recipe/dashboard/signin"),
75+
{
76+
email,
77+
password,
78+
}
79+
);
80+
utils_1.send200Response(options.res, signInResponse);
81+
return true;
82+
});
83+
}
84+
exports.default = signIn;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// @ts-nocheck
2+
import { APIInterface, APIOptions } from "../types";
3+
export default function signOut(_: APIInterface, options: APIOptions): Promise<boolean>;
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
"use strict";
2+
/* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved.
3+
*
4+
* This software is licensed under the Apache License, Version 2.0 (the
5+
* "License") as published by the Apache Software Foundation.
6+
*
7+
* You may not use this file except in compliance with the License. You may
8+
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
var __awaiter =
17+
(this && this.__awaiter) ||
18+
function (thisArg, _arguments, P, generator) {
19+
function adopt(value) {
20+
return value instanceof P
21+
? value
22+
: new P(function (resolve) {
23+
resolve(value);
24+
});
25+
}
26+
return new (P || (P = Promise))(function (resolve, reject) {
27+
function fulfilled(value) {
28+
try {
29+
step(generator.next(value));
30+
} catch (e) {
31+
reject(e);
32+
}
33+
}
34+
function rejected(value) {
35+
try {
36+
step(generator["throw"](value));
37+
} catch (e) {
38+
reject(e);
39+
}
40+
}
41+
function step(result) {
42+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
43+
}
44+
step((generator = generator.apply(thisArg, _arguments || [])).next());
45+
});
46+
};
47+
var __importDefault =
48+
(this && this.__importDefault) ||
49+
function (mod) {
50+
return mod && mod.__esModule ? mod : { default: mod };
51+
};
52+
Object.defineProperty(exports, "__esModule", { value: true });
53+
const utils_1 = require("../../../utils");
54+
const querier_1 = require("../../../querier");
55+
const normalisedURLPath_1 = __importDefault(require("../../../normalisedURLPath"));
56+
function signOut(_, options) {
57+
var _a;
58+
return __awaiter(this, void 0, void 0, function* () {
59+
if (options.config.apiKey) {
60+
utils_1.send200Response(options.res, { status: "OK" });
61+
} else {
62+
const sessionIdFormAuthHeader =
63+
(_a = options.req.getHeaderValue("authorization")) === null || _a === void 0
64+
? void 0
65+
: _a.split(" ")[1];
66+
let querier = querier_1.Querier.getNewInstanceOrThrowError(undefined);
67+
const sessionDeleteResponse = yield querier.sendDeleteRequest(
68+
new normalisedURLPath_1.default("/recipe/dashboard/session"),
69+
{},
70+
{ sessionId: sessionIdFormAuthHeader }
71+
);
72+
utils_1.send200Response(options.res, sessionDeleteResponse);
73+
}
74+
return true;
75+
});
76+
}
77+
exports.default = signOut;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ const utils_1 = require("../../../utils");
4949
const utils_2 = require("../utils");
5050
function validateKey(_, options) {
5151
return __awaiter(this, void 0, void 0, function* () {
52-
const shouldAllowAccess = yield options.recipeImplementation.shouldAllowAccess({
52+
const input = {
5353
req: options.req,
5454
config: options.config,
5555
userContext: utils_1.makeDefaultUserContextFromAPI(options.req),
56-
});
57-
if (!shouldAllowAccess) {
58-
utils_2.sendUnauthorisedAccess(options.res);
59-
} else {
56+
};
57+
if (yield utils_2.validateApiKey(input)) {
6058
options.res.sendJSONResponse({
6159
status: "OK",
6260
});
61+
} else {
62+
utils_2.sendUnauthorisedAccess(options.res);
6363
}
6464
return true;
6565
});

0 commit comments

Comments
 (0)