Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Feature/sms verification #78

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

Conversation

papotte
Copy link
Contributor

@papotte papotte commented Apr 13, 2020

Added (basic) SMS verification feature.

  • Some changes to Swagger in order to make navigation through the API slightly easier

Missing:

  • Database/real cache for managing phone number/OTP pairs

@papotte papotte requested a review from f10l April 13, 2020 22:56
@papotte papotte changed the title Feature/sms verification WIP: Feature/sms verification Apr 13, 2020
Copy link
Member

@f10l f10l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's looking very nice! I only made a few minor remarks.

Afterwards, we can already merge to develop and add with another PR the "real" validation of numbers.

TWILIO_ACCOUNT_SID=AC9b92504e0ef87d42765c1b338084abfb
TWILIO_API_KEY=SK803c26edc5e58ac78eccf7bc54789771
TWILIO_API_SECRET=ToKtCcu5ZnTXAod8XUO85iW86wphqrbG
SENDING_PHONE_NUMBER=+19386665491
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think another prefix is nice, the number belongs to twilio

Suggested change
SENDING_PHONE_NUMBER=+19386665491
TWILIO_SENDING_PHONE_NUMBER=+19386665491

TWILIO_API_SECRET=ToKtCcu5ZnTXAod8XUO85iW86wphqrbG
SENDING_PHONE_NUMBER=+19386665491
APP_HASH=randomhash
CLIENT_SECRET=verysecret
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is not really needed?
The name is a bit generic for a env.

Suggested change
CLIENT_SECRET=verysecret

TWILIO_API_KEY=SK803c26edc5e58ac78eccf7bc54789771
TWILIO_API_SECRET=ToKtCcu5ZnTXAod8XUO85iW86wphqrbG
SENDING_PHONE_NUMBER=+19386665491
APP_HASH=randomhash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the APP_HASH needed for?
If it's a debugging identifier, one could use the API_ROOT_URL

import { ApiProperty } from '@nestjs/swagger';

export class VerificationDto {
@ApiProperty({ example: '+49123456789' })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually not a valid number :-D Tobi used the same one for testing and was wondering ;-)

Suggested change
@ApiProperty({ example: '+49123456789' })
@ApiProperty({ example: '+491704567893' })

@@ -1,11 +1,6 @@
import { INestApplication } from '@nestjs/common';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you run npm run format on it? I Think swagger wants single lines here.


constructor(configService: ConfigurationService) {
let message = null;
if (configService.get('TWILIO_API_KEY') == null ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can leave all the validation for the moment, but should definitely build an env variable validation:

Suggested change
if (configService.get('TWILIO_API_KEY') == null ||
// TODO: build env variable validation
if (configService.get('TWILIO_API_KEY') == null ||

Comment on lines +33 to +34
console.log(message);
Logger.error('Twilio will not work!', message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log(message);
Logger.error('Twilio will not work!', message);
this.logger.error('Twilio will not work!', message);

if (otp == null) {
const message = 'No cached otp value found for phone: ' + phone;
this.logger.log(message);
throw new BadRequestException(message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a NotFoundException fit better? (request valid, but resource not there)

if (smsMessage.indexOf(otp) <= -1) {
const message = 'Mismatch between otp value found and otp value expected';
this.logger.log(message);
throw new BadRequestException(message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to keep BadRequest for input validation solely, maybe this could be a 422 (Unprocessable Entity).

if (otp == null) {
const message = 'No cached otp value found for phone: ' + phone;
this.logger.log(message);
throw new BadRequestException(message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above, maybe a NotFoundException

@f10l f10l linked an issue Apr 26, 2020 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add SMS for phone number validation
2 participants