-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,018 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
title: Authentication | ||
titleTemplate: The Boring JavaScript Stack 🥱 | ||
description: Authentication in The Boring JavaScript Stack | ||
prev: | ||
text: Sharing data | ||
link: '/boring-stack/sharing-data' | ||
next: | ||
text: Authorization | ||
link: '/boring-stack/authorization' | ||
editLink: true | ||
--- | ||
|
||
# {{ $frontmatter.title }} {#authentication} | ||
|
||
Authentication is the process of verifying the identity of a user, typically through credentials like a username and password. For example, logging into a GitHub account requires authentication. | ||
|
||
The Boring JavaScript Stack manages its own authentication. | ||
|
||
By default, the Boring JavaScript Stack offers you two mechanisms for authentication: | ||
|
||
1. Email and Password authentication | ||
2. Provider authentication | ||
|
||
## Email and password authentication | ||
|
||
When a user wishes to sign up for an account, they are asked for their email address. The Boring Stack will send them an email with a link to verify their email. The user can click the link to verify their email address. | ||
|
||
The password is stored using the bcrypt algorithm and handled by the password helper from [Sails organics](https://github.com/sailshq/sails-hook-organics). | ||
|
||
## Provider authentication | ||
|
||
Using [Sails Wish](/wish), The Boring Stack supports third-party authentication allowing you to easily add SSO(Single Sign On) to your application. Out of the box The Boring Stack supports [OAuth with Google](/wish/google). You can easily setup [OAuth with GitHub](/wish/github) as well. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
title: Authorization | ||
titleTemplate: The Boring JavaScript Stack 🥱 | ||
description: Authorization in The Boring JavaScript Stack | ||
prev: | ||
text: Authentication | ||
link: '/boring-stack/authentication' | ||
next: | ||
text: Database | ||
link: '/boring-stack/database' | ||
editLink: true | ||
--- | ||
|
||
# Authorization | ||
|
||
Authorization is the process of granting or denying access to specific resources or actions based on a user's authenticated identity. | ||
|
||
### Example Use Cases | ||
|
||
- **Admin access control:** Authorizing certain users to access and manage administrative functionalities. | ||
- **Content permissions:** Granting or denying users access to specific content or features based on their roles. | ||
- **Secure transactions:** Allowing authorized users to perform secure transactions or financial operations. | ||
|
||
Authorization within The Boring JavaScript Stack is orchestrated server-side through [Sails Policies](https://sailsjs.com/documentation/concepts/policies). These policies act as a shield, safeguarding your actions against unauthorized access. | ||
|
||
A common scenario involves permitting a user to access your dashboard exclusively when authenticated. To implement this, you can establish a `api/policies/is-authenticated.js` policy and then configure the actions you wish the policy to safeguard in `config/policies.js`: | ||
|
||
::: code-group | ||
|
||
```js [api/policies/is-authenticated.js] | ||
module.exports = async function (req, res, proceed) { | ||
if (req.session.userId) return proceed() | ||
return res.redirect('/login') | ||
} | ||
``` | ||
|
||
```js [config/policies.js] | ||
module.exports.policies = { | ||
'dashboard/*': 'is-authenticated' | ||
} | ||
``` | ||
|
||
::: | ||
|
||
::: info | ||
Learn more about using [policies](https://sailsjs.com/documentation/concepts/policies) for authorization on the Sails docs. | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
--- | ||
title: Database | ||
titleTemplate: The Boring JavaScript Stack 🥱 | ||
description: Database in The Boring JavaScript Stack | ||
prev: | ||
text: Authorization | ||
link: '/boring-stack/authorization' | ||
next: | ||
text: Email | ||
link: '/boring-stack/email' | ||
editLink: true | ||
--- | ||
|
||
# Database | ||
|
||
A database is a structured collection of data organized for efficient retrieval and management. In web development, databases store and manage information essential for applications, such as user data, content, and settings. | ||
|
||
### Example use cases | ||
|
||
- **User data storage:** Storing and retrieving user profiles, preferences, and account information. | ||
- **Content management:** Managing articles, posts, or any content within an application. | ||
- **Configuration settings:** Storing and managing application settings and configurations. | ||
|
||
## Sails Disk | ||
|
||
During development, The Boring JavaScript Stack utilizes the [Sails Disk](https://sailsjs.com/documentation/concepts/extending-sails/adapters/available-adapters#sails-disk) adapter for Waterline, allowing you to kickstart your app without worrying about setting up a database. | ||
|
||
::: info | ||
Learn more about [Sails Disk](https://sailsjs.com/documentation/concepts/extending-sails/adapters/available-adapters#?sailsdisk) on the Sails docs. | ||
::: | ||
|
||
## Setting up a database | ||
|
||
To set up a database, you can choose the adapter for your chosen database and follow the setup steps. | ||
|
||
## PostgreSQL | ||
|
||
::: code-group | ||
|
||
```sh [terminal] | ||
npm i sails-postgresql --save | ||
``` | ||
|
||
```js [config/datastores.js] | ||
module.exports.datastores = { | ||
default: { | ||
adapter: 'sails-postgresql', // [!code focus] | ||
url: 'postgresql://user:password@host:port/database' // [!code focus] | ||
} | ||
} | ||
``` | ||
|
||
::: | ||
|
||
## MySQL | ||
|
||
::: code-group | ||
|
||
```sh [terminal] | ||
npm i sails-mysql --save | ||
``` | ||
|
||
```js [config/datastores.js] | ||
module.exports.datastores = { | ||
default: { | ||
adapter: 'sails-mysql', // [!code focus] | ||
url: 'mysql://user:password@host:port/database' // [!code focus] | ||
} | ||
} | ||
``` | ||
|
||
::: | ||
|
||
## MongoDB | ||
|
||
::: code-group | ||
|
||
```sh [terminal] | ||
npm i sails-mongo --save | ||
``` | ||
|
||
```js [config/datastores.js] | ||
module.exports.datastores = { | ||
default: { | ||
adapter: 'sails-mongo', // [!code focus] | ||
url: 'mongodb://user:password@host:port/database' // [!code focus] | ||
} | ||
} | ||
``` | ||
|
||
::: | ||
|
||
## SQLite <Badge type="warning" text="coming soon" /> | ||
|
||
::: info | ||
The SQLite adapter is under development. You can keep an eye on the [repo](https://github.com/sailscastshq/sails-sqlite). | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
title: Email | ||
titleTemplate: The Boring JavaScript Stack 🥱 | ||
description: Sending emails in The Boring JavaScript Stack | ||
prev: | ||
text: Database | ||
link: '/boring-stack/database' | ||
next: | ||
text: Session | ||
link: '/boring-stack/session' | ||
editLink: true | ||
--- | ||
|
||
|
||
Sending transactional emails plays a crucial role in keeping users informed about specific actions or events. It involves delivering personalized and time-sensitive messages triggered by user interactions. | ||
|
||
### Example use cases | ||
|
||
- **User Registration Confirmation:** Sending an email to verify and confirm a user's registration. | ||
- **Password Reset Requests:** Notifying users and providing a secure link to reset their passwords. | ||
- **Order Confirmations:** Informing users about successful purchases with order details. | ||
|
||
Sending emails in The Boring JavaScript is powered by the [Sails Mail](/mail) hook. | ||
|
||
::: info | ||
Learn all about [Sails Mail](/mail) in the Mail docs. | ||
::: | ||
|
||
## Sending emails | ||
|
||
To send emails in The Boring JavaScript Stack, use the `sails.helpers.mail.send()` helper: | ||
|
||
```js | ||
// controllers/user/signup.js | ||
await sails.helpers.mail.send.with({ | ||
subject: 'Verify your email', | ||
template: 'email-verify-account', | ||
to: unverifiedUser.email, | ||
templateData: { | ||
token: unverifiedUser.emailProofToken, | ||
fullName: unverifiedUser.fullName | ||
} | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
title: Error handling | ||
titleTemplate: The Boring JavaScript Stack 🥱 | ||
description: Error handling in The Boring JavaScript Stack | ||
prev: | ||
text: Redirects | ||
link: '/boring-stack/redirects' | ||
next: | ||
text: Sharing data | ||
link: '/boring-stack/sharing-data' | ||
editLink: true | ||
--- | ||
|
||
# Error handling | ||
|
||
Coming soon :soon: |
Oops, something went wrong.