Skip to content

Commit c6e8771

Browse files
docs: General improvements on the docs based on community feedback (serverpod#381)
1 parent cea32b0 commit c6e8771

13 files changed

Lines changed: 210 additions & 36 deletions

File tree

docs/06-concepts/10-modules.md

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,30 @@
22

33
Serverpod is built around the concept of modules. A Serverpod module is similar to a Dart package but contains both server, client, and Flutter code. A module contains its own namespace for endpoints and methods to minimize the risk of conflicts.
44

5-
Examples of modules are the `serverpod_auth` module and the `serverpod_chat` module, which both are maintained by the Serverpod team.
5+
Examples of modules are the `serverpod_auth_core` and `serverpod_auth_idp` modules, which both are maintained by the Serverpod team.
66

77
## Adding a module to your project
88

99
### Server setup
1010

1111
To add a module to your project, you must include the server and client/Flutter packages in your project's `pubspec.yaml` files.
1212

13-
For example, to add the `serverpod_auth` module to your project, you need to add `serverpod_auth_server` to your server's `pubspec.yaml`:
13+
For example, to add the `serverpod_auth_idp` module to your project, you need to add `serverpod_auth_idp_server` to your server's `pubspec.yaml`:
1414

1515
```yaml
1616
dependencies:
17-
serverpod_auth_server: ^1.x.x
17+
serverpod_auth_idp_server: ^3.x.x
1818
```
1919
2020
:::info
21-
22-
Make sure to replace `1.x.x` with the Serverpod version you are using. Serverpod uses the same version number for all official packages. If you use the same version, you will be sure that everything works together.
23-
21+
Make sure to replace `3.x.x` with the Serverpod version you are using. Serverpod uses the same version number for all official packages. If you use the same version, you will be sure that everything works together.
2422
:::
2523

26-
In your `config/generator.yaml` you can optionally add the `serverpod_auth` module and give it a `nickname`. The nickname will determine how you reference the module from the client. If the module isn't added in the `generator.yaml`, the default nickname for the module will be used.
24+
In your `config/generator.yaml` you can optionally add the `serverpod_auth_idp` module and give it a `nickname`. The nickname will determine how you reference the module from the client. If the module isn't added in the `generator.yaml`, the default nickname for the module will be used.
2725

2826
```yaml
2927
modules:
30-
serverpod_auth:
28+
serverpod_auth_idp:
3129
nickname: auth
3230
```
3331

@@ -51,7 +49,7 @@ In your client's `pubspec.yaml`, you will need to add the generated client code
5149

5250
```yaml
5351
dependencies:
54-
serverpod_auth_client: ^1.x.x
52+
serverpod_auth_idp_client: ^3.x.x
5553
```
5654

5755
### Flutter app setup
@@ -60,19 +58,20 @@ In your Flutter app, add the corresponding dart or Flutter package(s) to your `p
6058

6159
```yaml
6260
dependencies:
63-
serverpod_auth_shared_flutter: ^1.x.x
64-
serverpod_auth_google_flutter: ^1.x.x
65-
serverpod_auth_apple_flutter: ^1.x.x
61+
serverpod_auth_idp_flutter: ^3.x.x
6662
```
6763

6864
## Referencing a module
6965

70-
It can be useful to reference serializable objects in other modules from the YAML-files in your models. You do this by adding the module prefix, followed by the nickname of the package. For instance, this is how you reference a serializable class in the auth package.
66+
It can be useful to reference serializable objects in other modules from the YAML-files in your models. You do this by adding the module prefix, followed by the nickname of the package. For instance, this is how you reference a serializable class in the `serverpod_auth_idp` package.
7167

7268
```yaml
7369
class: MyClass
7470
fields:
75-
userInfo: module:auth:UserInfo
71+
# Using the full module name
72+
userInfo: module:serverpod_auth_idp:AuthUser
73+
# Or using the nickname
74+
userInfo: module:auth:AuthUser
7675
```
7776

7877
## Creating custom modules
@@ -92,7 +91,5 @@ $ flutter create --template package my_module_flutter
9291
In your Flutter package, you most likely want to import the client libraries created by `serverpod create`.
9392

9493
:::info
95-
9694
Most modules will need a set of database tables to function. When naming the tables, you should use the module name as a prefix to the table name to avoid any conflicts. For instance, the Serverpod tables are prefixed with `serverpod_`.
97-
9895
:::

docs/06-concepts/11-authentication/01-setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Serverpod comes with built-in user management and authentication. It is possible
44

55
The list of identity providers is continuously growing and new providers are added as they are developed. If you want to contribute a new provider, please consider [contributing](/contribute) your code. See the [identity providers configuration](#identity-providers-configuration) section for details on all available providers.
66

7-
![Sign-in with Serverpod](/img/authentication/sign-in-widget.png)
7+
![Sign-in with Serverpod](/img/authentication/sign-in-widget-device.png)
88

99
## Installing the auth module
1010

docs/06-concepts/11-authentication/03-working-with-users.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Working with users
22

3-
The authentication module provides conventient ways to work with your authenticated users and their related profile data.
3+
The authentication module provides convenient ways to work with your authenticated users and their related profile data.
44

55
## Authenticated users
66

@@ -40,6 +40,30 @@ await AuthServices.instance.userProfiles.changeFullName(session, authUserId, 'my
4040

4141
For the full list of operations, see the [UserProfiles](https://pub.dev/documentation/serverpod_auth_core_server/latest/serverpod_auth_core_server/UserProfiles-class.html) class documentation.
4242

43+
### Setting a default user image
44+
45+
When logging in from some providers, the user image is automatically fetched and set as the user's profile picture - such as with Google Sign In. However, when an image is not found or the provider does not expose the picture, it is possible to set a default user image using the `UserProfileConfig` object.
46+
47+
```dart
48+
pod.initializeAuthServices(
49+
userProfileConfig: UserProfileConfig(
50+
// NOTE: The `userImageGenerator` parameter is optional and defaults to
51+
// the value below - which generates Gmail-style images. You can change
52+
// this parameter to generate any kind of placeholder image. The function
53+
// will be called when invoking the `setDefaultUserImage` method.
54+
userImageGenerator: defaultUserImageGenerator,
55+
onAfterUserProfileCreated:
56+
(session, userProfile, {required transaction}) async {
57+
await AuthServices.instance.userProfiles.setDefaultUserImage(
58+
session,
59+
userProfile.authUserId,
60+
transaction: transaction,
61+
);
62+
},
63+
),
64+
...
65+
);
66+
```
4367

4468
## Attaching additional information
4569

@@ -59,6 +83,11 @@ indexes:
5983
unique: true
6084
```
6185
86+
:::tip
87+
When referencing module classes in your model files, you can use a nickname for the module instead of the full module name. See the [modules documentation](../modules) for more information.
88+
:::
89+
90+
6291
The model above creates a relation to the `AuthUser` table and ensures that each user can only have one `MyDomainData` object. The `onDelete=Cascade` ensures that when the `AuthUser` is deleted, the `MyDomainData` object is also deleted.
6392

6493
This makes it easy to query the additional information later based on the user's `authId`.

docs/06-concepts/11-authentication/04-providers/01-email/02-configuration.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,25 @@ final emailIdpConfig = EmailIdpConfigFromPasswords(
6767
Remember to configure the `verificationCodeConfig` parameter on the `EmailSignInWidget` to match the length of the verification code you generate. Otherwise, users will never be able to enter the verification code correctly. See the [customizing the UI section](./customizing-the-ui) for more details.
6868
:::
6969

70+
#### Bypassing verification code in development
71+
72+
To simplify testing, it is possible to bypass the verification code by using a custom verification code generator that always returns the same code. This can be configured only for the development run mode as below:
73+
74+
```dart
75+
pod.initializeAuthServices(
76+
tokenManagerBuilders: [
77+
JwtConfigFromPasswords(),
78+
],
79+
identityProviderBuilders: [
80+
EmailIdpConfigFromPasswords(
81+
registrationVerificationCodeGenerator: pod.runMode == 'development'
82+
? () => 'aaaaaaaa' // Be sure to match the length used in production.
83+
: defaultVerificationCodeGenerator,
84+
),
85+
],
86+
);
87+
```
88+
7089
### Reacting to events
7190

7291
Beyond the `sendRegistrationVerificationCode` and `sendPasswordResetVerificationCode` callbacks to send verification codes to the user, there are a few callbacks that can be used to react to events, such as `onAfterAccountCreated` and `onPasswordResetCompleted`. These can be useful for sending emails to the user to communicate the successful operation.

docs/06-concepts/11-authentication/04-providers/02-google/02-configuration.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,25 @@ final googleIdpConfig = GoogleIdpConfigFromPasswords(
100100
},
101101
);
102102
```
103+
104+
### Lightweight Sign-In on the Flutter app
105+
106+
Lightweight sign-in is a feature that attempts to authenticate users previously logged in with Google automatically with minimal or no user interaction. When enabled, the Google authentication controller will try to sign in users seamlessly using platform-specific lightweight authentication methods. This feature is enabled by default, but can be disabled from the `GoogleSignInWidget` or `GoogleAuthController`.
107+
108+
```dart
109+
GoogleSignInWidget(
110+
client: client,
111+
attemptLightweightSignIn: false, // Disable lightweight sign-in
112+
onAuthenticated: () {
113+
// User was automatically signed in
114+
},
115+
)
116+
```
117+
118+
:::info
119+
If lightweight sign-in fails (e.g., no previous session exists or the user dismisses the prompt), the user can still use the regular sign-in button to authenticate manually.
120+
:::
121+
122+
:::note
123+
The lightweight sign-in attempt happens automatically when the controller is initialized, typically at app launch. If successful, users will be signed in without any additional interaction.
124+
:::

docs/08-upgrading/01-upgrade-to-three.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,30 @@ class MyEndpoint extends Endpoint {
241241

242242
Serverpod 3.0 includes several changes to the authentication system that improve type safety and performance.
243243

244+
### Custom authentication handlers
245+
246+
In the new authentication system, the default authentication header has changed from `Basic` to `Bearer` - which is now officially supported. This introduced a change for custom `AuthenticationHandler` implementations: the `token` parameter will now receive the token unwrapped from the `Bearer` prefix - just as it does for `Basic` tokens.
247+
248+
If your application relies on the default `authenticationHandler` function, no change is required. Only custom implementations that previously implemented `Bearer` authentication will need to be updated to expect the unwrapped token.
249+
250+
Another change when using custom authentication handlers is that tokens without scheme prefix are no longer supported by default to enforce HTTP header standards. The preferred fix is to wrap the token with the `Bearer` prefix, but this will invalidate existing tokens. If you are you are using a custom authentication handler in production and need to keep the old behavior, you can set the `validateHeaders` parameter to `false` in your `production.yaml` config file.
251+
252+
```yaml
253+
apiServer:
254+
...
255+
256+
insightsServer:
257+
...
258+
259+
webServer:
260+
...
261+
262+
validateHeaders: false # <-- Add this line
263+
264+
sessionLogs:
265+
consoleEnabled: false
266+
```
267+
244268
### AuthenticationInfo changes
245269

246270
The `AuthenticationInfo` class has been updated:
49.3 KB
Loading

versioned_docs/version-3.0.0/06-concepts/10-modules.md

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,30 @@
22

33
Serverpod is built around the concept of modules. A Serverpod module is similar to a Dart package but contains both server, client, and Flutter code. A module contains its own namespace for endpoints and methods to minimize the risk of conflicts.
44

5-
Examples of modules are the `serverpod_auth` module and the `serverpod_chat` module, which both are maintained by the Serverpod team.
5+
Examples of modules are the `serverpod_auth_core` and `serverpod_auth_idp` modules, which both are maintained by the Serverpod team.
66

77
## Adding a module to your project
88

99
### Server setup
1010

1111
To add a module to your project, you must include the server and client/Flutter packages in your project's `pubspec.yaml` files.
1212

13-
For example, to add the `serverpod_auth` module to your project, you need to add `serverpod_auth_server` to your server's `pubspec.yaml`:
13+
For example, to add the `serverpod_auth_idp` module to your project, you need to add `serverpod_auth_idp_server` to your server's `pubspec.yaml`:
1414

1515
```yaml
1616
dependencies:
17-
serverpod_auth_server: ^1.x.x
17+
serverpod_auth_idp_server: ^3.x.x
1818
```
1919
2020
:::info
21-
22-
Make sure to replace `1.x.x` with the Serverpod version you are using. Serverpod uses the same version number for all official packages. If you use the same version, you will be sure that everything works together.
23-
21+
Make sure to replace `3.x.x` with the Serverpod version you are using. Serverpod uses the same version number for all official packages. If you use the same version, you will be sure that everything works together.
2422
:::
2523

26-
In your `config/generator.yaml` you can optionally add the `serverpod_auth` module and give it a `nickname`. The nickname will determine how you reference the module from the client. If the module isn't added in the `generator.yaml`, the default nickname for the module will be used.
24+
In your `config/generator.yaml` you can optionally add the `serverpod_auth_idp` module and give it a `nickname`. The nickname will determine how you reference the module from the client. If the module isn't added in the `generator.yaml`, the default nickname for the module will be used.
2725

2826
```yaml
2927
modules:
30-
serverpod_auth:
28+
serverpod_auth_idp:
3129
nickname: auth
3230
```
3331

@@ -51,7 +49,7 @@ In your client's `pubspec.yaml`, you will need to add the generated client code
5149

5250
```yaml
5351
dependencies:
54-
serverpod_auth_client: ^1.x.x
52+
serverpod_auth_idp_client: ^3.x.x
5553
```
5654

5755
### Flutter app setup
@@ -60,19 +58,20 @@ In your Flutter app, add the corresponding dart or Flutter package(s) to your `p
6058

6159
```yaml
6260
dependencies:
63-
serverpod_auth_shared_flutter: ^1.x.x
64-
serverpod_auth_google_flutter: ^1.x.x
65-
serverpod_auth_apple_flutter: ^1.x.x
61+
serverpod_auth_idp_flutter: ^3.x.x
6662
```
6763

6864
## Referencing a module
6965

70-
It can be useful to reference serializable objects in other modules from the YAML-files in your models. You do this by adding the module prefix, followed by the nickname of the package. For instance, this is how you reference a serializable class in the auth package.
66+
It can be useful to reference serializable objects in other modules from the YAML-files in your models. You do this by adding the module prefix, followed by the nickname of the package. For instance, this is how you reference a serializable class in the `serverpod_auth_idp` package.
7167

7268
```yaml
7369
class: MyClass
7470
fields:
75-
userInfo: module:auth:UserInfo
71+
# Using the full module name
72+
userInfo: module:serverpod_auth_idp:AuthUser
73+
# Or using the nickname
74+
userInfo: module:auth:AuthUser
7675
```
7776

7877
## Creating custom modules
@@ -92,7 +91,5 @@ $ flutter create --template package my_module_flutter
9291
In your Flutter package, you most likely want to import the client libraries created by `serverpod create`.
9392

9493
:::info
95-
9694
Most modules will need a set of database tables to function. When naming the tables, you should use the module name as a prefix to the table name to avoid any conflicts. For instance, the Serverpod tables are prefixed with `serverpod_`.
97-
9895
:::

versioned_docs/version-3.0.0/06-concepts/11-authentication/01-setup.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Serverpod comes with built-in user management and authentication. It is possible
44

55
The list of identity providers is continuously growing and new providers are added as they are developed. If you want to contribute a new provider, please consider [contributing](/contribute) your code. See the [identity providers configuration](#identity-providers-configuration) section for details on all available providers.
66

7-
![Sign-in with Serverpod](/img/authentication/sign-in-widget.png)
7+
![Sign-in with Serverpod](/img/authentication/sign-in-widget-device.png)
88

99
## Installing the auth module
1010

@@ -60,6 +60,14 @@ void run(List<String> args) async {
6060
}
6161
```
6262

63+
Then, extend the abstract endpoint for refreshing JWT tokens to expose it on the server:
64+
65+
```dart
66+
import 'package:serverpod_auth_idp_server/core.dart' as core;
67+
68+
class RefreshJwtTokensEndpoint extends core.RefreshJwtTokensEndpoint {}
69+
```
70+
6371
### Token Manager Configuration
6472

6573
The authentication system uses token managers to handle authentication tokens. You need to configure at least one token manager to be used as the primary token manager. Additional token managers can be configured to be used for validation and management operations.

versioned_docs/version-3.0.0/06-concepts/11-authentication/03-working-with-users.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Working with users
22

3-
The authentication module provides conventient ways to work with your authenticated users and their related profile data.
3+
The authentication module provides convenient ways to work with your authenticated users and their related profile data.
44

55
## Authenticated users
66

@@ -40,6 +40,30 @@ await AuthServices.instance.userProfiles.changeFullName(session, authUserId, 'my
4040

4141
For the full list of operations, see the [UserProfiles](https://pub.dev/documentation/serverpod_auth_core_server/latest/serverpod_auth_core_server/UserProfiles-class.html) class documentation.
4242

43+
### Setting a default user image
44+
45+
When logging in from some providers, the user image is automatically fetched and set as the user's profile picture - such as with Google Sign In. However, when an image is not found or the provider does not expose the picture, it is possible to set a default user image using the `UserProfileConfig` object.
46+
47+
```dart
48+
pod.initializeAuthServices(
49+
userProfileConfig: UserProfileConfig(
50+
// NOTE: The `userImageGenerator` parameter is optional and defaults to
51+
// the value below - which generates Gmail-style images. You can change
52+
// this parameter to generate any kind of placeholder image. The function
53+
// will be called when invoking the `setDefaultUserImage` method.
54+
userImageGenerator: defaultUserImageGenerator,
55+
onAfterUserProfileCreated:
56+
(session, userProfile, {required transaction}) async {
57+
await AuthServices.instance.userProfiles.setDefaultUserImage(
58+
session,
59+
userProfile.authUserId,
60+
transaction: transaction,
61+
);
62+
},
63+
),
64+
...
65+
);
66+
```
4367

4468
## Attaching additional information
4569

@@ -59,6 +83,11 @@ indexes:
5983
unique: true
6084
```
6185
86+
:::tip
87+
When referencing module classes in your model files, you can use a nickname for the module instead of the full module name. See the [modules documentation](../modules) for more information.
88+
:::
89+
90+
6291
The model above creates a relation to the `AuthUser` table and ensures that each user can only have one `MyDomainData` object. The `onDelete=Cascade` ensures that when the `AuthUser` is deleted, the `MyDomainData` object is also deleted.
6392

6493
This makes it easy to query the additional information later based on the user's `authId`.

0 commit comments

Comments
 (0)