- Change existing data model guides and add new ones for DML - Change module's docs around service factory + remove guides that are now necessary - Hide/remove all mentions of module relationships, or label them as coming soon. - Change all data model creation snippets to use DML - use `property` instead of `field` when referring to a data model's properties. - Fix all snippets in commerce module guides to use new method suffix (no more main model methods) - Rework recipes, removing/hiding a lot of sections as a lot of recipes are incomplete with the current state of DML. ### Other changes - Highlight fixes in some guides - Remove feature flags guide - Fix code block styles when there are no line numbers. ### Upcoming changes in other PRs - Re-generate commerce module references (for the updates in the method names) - Ensure that the data model references are generated correctly for models using DML. - (probably at a very later point) revisit recipes
98 lines
2.9 KiB
Plaintext
98 lines
2.9 KiB
Plaintext
---
|
||
sidebar_label: "Authentication Flows"
|
||
---
|
||
|
||
export const metadata = {
|
||
title: `Authentication Flows with the Auth Provider`,
|
||
}
|
||
|
||
# {metadata.title}
|
||
|
||
In this document, you'll learn about how the Auth Provider is used in an authentication flow.
|
||
|
||
## How to Authenticate a User
|
||
|
||
To authenticate a user, you use the [authenticate method of the Auth Module's main service](/references/auth/authenticate). For example:
|
||
|
||
```ts
|
||
const data = await authModuleService.authenticate(
|
||
"emailpass",
|
||
// passed to auth provider
|
||
{
|
||
// ...
|
||
}
|
||
)
|
||
```
|
||
|
||
This method calls the `authenticate` method of the provider specified in the first parameter and returns its data.
|
||
|
||
---
|
||
|
||
## Basic Authentication Flow
|
||
|
||
If the `authenticate` method returns the following object:
|
||
|
||
```ts
|
||
data = {
|
||
success: true,
|
||
authIdentity: {
|
||
// ...
|
||
},
|
||
}
|
||
```
|
||
|
||
Then, the user is authenticated successfully, and their authentication details are available within the `authIdentity` object.
|
||
|
||
<Note>
|
||
|
||
Check out the [AuthIdentity](/references/auth/models/AuthIdentity) reference for the expected properties in `authIdentity`.
|
||
|
||
</Note>
|
||
|
||

|
||
|
||
---
|
||
|
||
## Authentication with Third-Party Service Flow
|
||
|
||
If the `authenticate` method returns the following object:
|
||
|
||
```ts
|
||
data = {
|
||
success: true,
|
||
location: "https://....",
|
||
}
|
||
```
|
||
|
||
It means the authentication process requires the user to perform an action with a third-party service. For example, when using the `google` provider, the user goes to the URL specified in the `location`'s value to log in with their Google account.
|
||
|
||

|
||
|
||
### validateCallback
|
||
|
||
Providers handling this authentication flow must implement the `validateCallback` method. It implements the logic to validate the authentication with the third-party service.
|
||
|
||
So, once the user performs the required action, the third-party service must redirect to an API route that uses the [validateCallback method of the Auth Module's main service](/references/auth/validateCallback). The method calls the specified provider’s `validateCallback` method passing it the authentication details it received in the second parameter:
|
||
|
||
```ts
|
||
const data = await authModuleService.validateCallback(
|
||
"google",
|
||
// passed to auth provider
|
||
{
|
||
// ...
|
||
}
|
||
)
|
||
```
|
||
|
||
If the authentication is successful, the `validateCallback` method returns the same data as the basic authentication:
|
||
|
||
```ts
|
||
data = {
|
||
success: true,
|
||
authIdentity: {
|
||
// ...
|
||
},
|
||
}
|
||
```
|
||
|
||
 |