Repository
https://github.com/creatrixity/adonis-auth-scaffold
Pull Request
https://github.com/creatrixity/adonis-auth-scaffold/pull/6
Continuing with the development of the authentications scaffold for Adonis, this feature adds greater flexibility alongside a much more flexible means of getting solid, tested authentications system out of the box for your Adonis project.
Correspondence from adonis-auth-scaffold
viewers indicated that a lot of correspondents have API clients as primary use cases for their Adonis apps and were not invested in the current feature stack. Crafting a custom solution for API client consumers while maintaining interchangeability with current implementations already in production was important.
To strike a proper balance, it was important to be able to properly customize the use case for the CLI generator. Solving this problem involved using the graciously provided Adonis Ace helpers. The code below helps with ensuring a prompt is provided if the user does not supply either the --api-only
or --http-only
required flags.
async handle({}, {
apiOnly,
httpOnly
}) {
let client;
if (!apiOnly && !httpOnly) {
client = await this
.choice('Will this be used for a REST Api or for a HTTP Client?', [
{
name: 'For REST Api',
value: 'api'
}, {
name: 'For HTTP',
value: 'http'
}
])
} else {
client = apiOnly ? 'api': 'http';
}
// Rest of method...
}
To improve the user experience for the package, it is important to keep user effort to a minimum. To this end, it was important to provide a way of writing code to already existing Adonis files. The code below adds a new line of code after the first line of start/routes.js
// Write a module require statement to the routes.js file.
let routesFilePath = path.join(Helpers.appRoot(), 'start/routes.js');
let generatedRoutesFilename = apiOnly ? 'apiAuthRoutes.js': 'authRoutes.js';
await this._prependLineToFile({
filename: routesFilePath,
lineNumber: 2,
lineContent: `require('./${generatedRoutesFilename}');`
})
The prependLineToFile
method is defined below. This method takes a fully qualified filename (file path and name), a line number to have the new code inserted and the content to be inserted.
/**
* Prepends a line of text to a provided file.
*
* @param {String} Object.filename - Fully qualified path of the file to be operated on.
* @param {Number} Object.lineNumber - Line to operate on.
* @param {String} Object.lineContent - Content to be prepended.
*
* @return {Void}
*/
async _prependLineToFile ({
filename,
lineNumber,
lineContent
}) {
let fileContents = await this.readFile(filename, 'utf-8');
fileContents = fileContents.split("\n");
if (fileContents[lineNumber] === lineContent) return;
fileContents.splice(lineNumber, 0, `\n${lineContent}\n`)
await this.writeFile(filename, fileContents.join('\n'));
}
What's next?
- Provide further code documentation for existing code.
- Write improved documentation on current features.
Thank you for your contribution.
You probably can use a single variable
mode
(which can be enum) to determine if it is API or REST, which will make the logics a lot simpler.The copyAppStarterFiles appears to me requiring a parameter client, but on the code, it passes nothing, do this code work?
For the line append/prepend, have you considered the line endings on Linux, Windows or MAC?
\n
,\n\r
or\r
?You may want to check if a file has been prepended using a better approach rather than
if (fileContents[lineNumber] === lineContent) return;
.Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.
To view those questions and the relevant answers related to your post, click here.
Need help? Chat with us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Great insight. The v1.1.1 fix will address these issues.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you for your review, @justyy! Keep up the good work!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hey, @creatrixity!
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!
Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).
Want to chat? Join us on Discord https://discord.gg/h52nFrV.
Vote for Utopian Witness!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @creatrixity! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :
You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
Do not miss the last post from @steemitboard:
Vote for @Steemitboard as a witness to get one more award and increased upvotes!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @creatrixity! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit