Conversation
| "api" | ||
| ], | ||
| "private": true, | ||
| "author": "Saugat Acharya <mesaugat@gmail.com>", |
There was a problem hiding this comment.
You can keep this. Instead, add your name too in a separate contributors list.
| if (tokenType !== 'Bearer' || !token) { | ||
| return { | ||
| ok: false, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| token, | ||
| }; |
There was a problem hiding this comment.
Why different results in between cases? I think it could only be - token or null OR token or error.
There was a problem hiding this comment.
Generally, user of the API when we tend to return null, undefined, "" or throws have the tendency to check for the error like so:
if (!token){}
OR
if (token === ""){}
OR
try{ // statements }catch(err){}
all of which are optional if user choose not to handle the error properly.
Agreed that return signature and method is a bit verbose here, however i think it forces dev to handle error explicitly. Allows dev to treat error as just another value.
Any thoughts? This is not the typical JS standard way of error handling however languages like go, rust follows the Tuple/Enum pattern.
|
|
||
| if (tokenType !== 'Bearer' || !token) { | ||
| return { | ||
| ok: false, |
There was a problem hiding this comment.
Make it straight. Either return null to signify empty value or throw an error to state the failure -- nothing in between.
src/utils/logger.js
Outdated
| const LOG_DIR = process.env.LOG_DIR || 'logs'; | ||
| const LOG_LEVEL = process.env.LOG_LEVEL || 'info'; | ||
|
|
||
| const isFileLogEnabled = process.env.ENABLE_FILE_LOG === 'TRUE'; |
There was a problem hiding this comment.
Make it consistent with other LOG_ env variables.
process.env.LOG_ENABLE_FILE_TRANSPORTThere was a problem hiding this comment.
@mesaugat, its acts as a flag, may be maintain consistency over semantics? I think ENABLE_FILE_LOG_TRANSPORT is easier to reason?
There was a problem hiding this comment.
I'd choose consistency because in the long run these variables will grow and it will be a mess.
It's for you to decide.
|
|
||
| import swaggerSpec from './utils/swagger'; | ||
| import userRoutes from './routes/userRoutes'; | ||
| import userRoutes from './routes/user'; |
There was a problem hiding this comment.
A bharyang would look nice.
import userRoutes from './route/user';
import authenticateUser from './auth';
import swaggerSpec from './utils/swagger';| const { ok, token } = extractTokenFromHeaders(req.headers); | ||
|
|
||
| if (!ok) { |
There was a problem hiding this comment.
Couldn't be more simple than this.
| const { ok, token } = extractTokenFromHeaders(req.headers); | |
| if (!ok) { | |
| const token = extractTokenFromHeaders(req.headers); | |
| if (!token) { |
Completed
Need to be done: