Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
♻️ Remove fallback from TWT
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Aug 4, 2020
1 parent 3f3ccf1 commit 8cae267
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/_staart/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const localsToTokenOrKey = (res: Response) => {
if (res.locals.token.sub == Tokens.API_KEY) {
return res.locals.token as ApiKeyResponse;
}
return res.locals.token.id as string;
return res.locals.token.id as number;
};

export const safeRedirect = (req: Request, res: Response, url: string) => {
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
verifyEmail,
} from "../../_staart/rest/auth";
import { addInvitationCredits } from "../../_staart/rest/user";
import { twtToId } from "../../_staart/helpers/utils";

export class AuthController {
@Post("register")
Expand Down Expand Up @@ -192,7 +193,7 @@ export class AuthController {
)
async getImpersonate(req: Request, res: Response) {
const tokenUserId = res.locals.token.id;
const impersonateUserId = req.params.id;
const impersonateUserId = twtToId(req.params.id);
return impersonate(tokenUserId, impersonateUserId, res.locals);
}

Expand Down
10 changes: 5 additions & 5 deletions src/controllers/users/_id/access-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
export class UserAccessTokensController {
@Get()
async getUserAccessTokens(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
joiValidate({ id: Joi.string().required() }, { id });
return getUserAccessTokensForUser(res.locals.token.id, id, req.query);
}
Expand All @@ -47,7 +47,7 @@ export class UserAccessTokensController {
)
)
async putUserAccessTokens(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
joiValidate({ id: Joi.string().required() }, { id });
try {
const added = await createAccessTokenForUser(
Expand All @@ -65,7 +65,7 @@ export class UserAccessTokensController {

@Get(":accessTokenId")
async getUserAccessToken(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
const accessTokenId = req.params.accessTokenId;
joiValidate(
{
Expand All @@ -90,7 +90,7 @@ export class UserAccessTokensController {
)
)
async patchUserAccessToken(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
const accessTokenId = req.params.accessTokenId;
joiValidate(
{
Expand All @@ -111,7 +111,7 @@ export class UserAccessTokensController {

@Delete(":accessTokenId")
async deleteUserAccessToken(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
const accessTokenId = req.params.accessTokenId;
joiValidate(
{
Expand Down
10 changes: 5 additions & 5 deletions src/controllers/users/_id/emails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ import {
export class UserEmailsController {
@Get()
async getEmails(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
joiValidate({ id: Joi.string().required() }, { id });
return getAllEmailsForUser(res.locals.token.id, id, req.query);
}

@Put()
async putEmails(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
const email = req.body.email;
joiValidate(
{
Expand All @@ -55,7 +55,7 @@ export class UserEmailsController {

@Get(":emailId")
async getEmail(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
const emailId = req.params.emailId;
joiValidate(
{
Expand All @@ -69,7 +69,7 @@ export class UserEmailsController {

@Post(":emailId/resend")
async postResend(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
const emailId = req.params.emailId;
joiValidate(
{
Expand All @@ -84,7 +84,7 @@ export class UserEmailsController {

@Delete(":emailId")
async deleteEmail(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
const emailId = req.params.emailId;
joiValidate(
{
Expand Down
10 changes: 5 additions & 5 deletions src/controllers/users/_id/identities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ import {
export class UserIdentitiesController {
@Get()
async getUserIdentities(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
joiValidate({ id: Joi.string().required() }, { id });
return getUserIdentitiesForUser(res.locals.token.id, id, req.query);
}

@Put()
async createUserIdentity(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
joiValidate({ id: Joi.string().required() }, { id });
const added = await createUserIdentityForUser(
res.locals.token.id,
Expand All @@ -47,7 +47,7 @@ export class UserIdentitiesController {

@Post(":service")
async connectUserIdentity(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
joiValidate({ id: Joi.string().required() }, { id });
const service = req.params.service;
const url = req.body.url;
Expand All @@ -61,7 +61,7 @@ export class UserIdentitiesController {

@Get(":identityId")
async getUserIdentity(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
const identityId = req.params.identityId;
joiValidate(
{
Expand All @@ -75,7 +75,7 @@ export class UserIdentitiesController {

@Delete(":identityId")
async deleteUserIdentity(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
const identityId = req.params.identityId;
joiValidate(
{
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/users/_id/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
export class UserController {
@Get()
async get(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
joiValidate({ id: Joi.string().required() }, { id });
return getUserFromIdForUser(id, res.locals.token.id, req.query);
}
Expand Down Expand Up @@ -59,7 +59,7 @@ export class UserController {
)
)
async patch(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
joiValidate({ id: Joi.string().required() }, { id });
const updated = await updateUserForUser(
res.locals.token.id,
Expand All @@ -72,7 +72,7 @@ export class UserController {

@Delete()
async delete(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
joiValidate({ id: Joi.string().required() }, { id });
await deleteUserForUser(res.locals.token.id, id, res.locals);
return respond(RESOURCE_DELETED);
Expand Down
8 changes: 4 additions & 4 deletions src/controllers/users/_id/memberships.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import {
export class UserMembershipsController {
@Get()
async getMemberships(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
joiValidate({ id: Joi.string().required() }, { id });
return getMembershipsForUser(res.locals.token.id, id, req.query);
}

@Get(":membershipId")
async getMembership(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
const membershipId = req.params.membershipId;
joiValidate(
{
Expand All @@ -42,7 +42,7 @@ export class UserMembershipsController {

@Delete(":membershipId")
async deleteMembership(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
const membershipId = req.params.membershipId;
joiValidate(
{
Expand All @@ -57,7 +57,7 @@ export class UserMembershipsController {

@Patch(":membershipId")
async updateMembership(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
const membershipId = req.params.membershipId;
joiValidate(
{
Expand Down
12 changes: 6 additions & 6 deletions src/controllers/users/_id/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class UserSecurityController {
)
)
async updatePassword(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
const oldPassword = req.body.oldPassword;
const newPassword = req.body.newPassword;
joiValidate(
Expand All @@ -55,21 +55,21 @@ export class UserSecurityController {

@Get("data")
async getUserData(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
joiValidate({ id: Joi.string().required() }, { id });
return getAllDataForUser(res.locals.token.id, id);
}

@Get("2fa/enable")
async getEnable2FA(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
joiValidate({ id: Joi.string().required() }, { id });
return enable2FAForUser(res.locals.token.id, id);
}

@Post("2fa/verify")
async postVerify2FA(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
const code = req.body.code;
joiValidate(
{
Expand All @@ -84,15 +84,15 @@ export class UserSecurityController {

@Delete("2fa")
async delete2FA(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
joiValidate({ id: Joi.string().required() }, { id });
await disable2FAForUser(res.locals.token.id, id);
return respond(RESOURCE_SUCCESS);
}

@Get("backup-codes/regenerate")
async getRegenerateBackupCodes(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
joiValidate({ id: Joi.string().required() }, { id });
const backupCodes = await regenerateBackupCodesForUser(
res.locals.token.id,
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/users/_id/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import {
export class UserSessionsController {
@Get()
async getUserSessions(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
joiValidate({ id: Joi.string().required() }, { id });
return getUserSessionsForUser(res.locals.token.id, id, req.query);
}

@Get(":sessionId")
async getUserSession(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
const sessionId = req.params.sessionId;
joiValidate(
{
Expand All @@ -40,7 +40,7 @@ export class UserSessionsController {

@Delete(":sessionId")
async deleteUserSession(req: Request, res: Response) {
const id = twtToId(req.params.id, res.locals.token.id);
const id = twtToId(req.params.id);
const sessionId = req.params.sessionId;
joiValidate(
{
Expand Down

0 comments on commit 8cae267

Please sign in to comment.