Skip to content

Commit faa88bd

Browse files
docs: Add docs on how to access user profile from the app (#399)
1 parent 4975606 commit faa88bd

4 files changed

Lines changed: 264 additions & 0 deletions

File tree

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,72 @@ await AuthServices.instance.userProfiles.changeFullName(session, authUserId, 'my
6868

6969
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.
7070

71+
### Accessing user profiles from the app
72+
73+
To access the user profile from your Flutter app, you can use the `userProfileInfo` endpoint that is included in the authentication module:
74+
75+
```dart
76+
final userProfile = await client.modules.serverpod_auth_core.userProfileInfo.get();
77+
```
78+
79+
This returns a `UserProfileModel` object containing the logged-in user's profile information such as their name, email, and profile picture.
80+
81+
### Extending the user profile edit endpoint
82+
83+
The authentication module provides a `UserProfileEditBaseEndpoint` abstract class that you can extend to expose user profile editing functionality to your app. This base endpoint includes methods for:
84+
85+
- Removing user images
86+
- Setting user images
87+
- Changing user names
88+
- Changing full names
89+
90+
To enable profile editing in your app, create a concrete endpoint class on your server by extending `UserProfileEditBaseEndpoint`:
91+
92+
```dart
93+
import 'package:serverpod/serverpod.dart';
94+
import 'package:serverpod_auth_idp_server/core.dart';
95+
96+
class UserProfileEditEndpoint extends UserProfileEditBaseEndpoint {}
97+
```
98+
99+
This endpoint will have both `get` (same as `userProfileInfo`) and all profile editing methods. You can then call these methods from your Flutter app:
100+
101+
```dart
102+
// Get the user's profile
103+
final profile = await client.userProfileEdit.get();
104+
105+
// Change the user's full name
106+
final updatedProfile = await client.userProfileEdit.changeFullName('John Doe');
107+
108+
// Change the user's username
109+
final updatedProfile = await client.userProfileEdit.changeUserName('johndoe');
110+
111+
// Remove the user's profile image
112+
final updatedProfile = await client.userProfileEdit.removeUserImage();
113+
114+
// Set a new profile image
115+
final ByteData imageData = // ... load image data
116+
final updatedProfile = await client.userProfileEdit.setUserImage(imageData);
117+
```
118+
119+
:::note
120+
The `UserProfileEditBaseEndpoint` requires authentication and operates on the currently authenticated user's profile.
121+
:::
122+
123+
You can also extend the endpoint class to add custom profile editing functionality:
124+
125+
```dart
126+
class UserProfileEditEndpoint extends UserProfileEditBaseEndpoint {
127+
Future<UserProfileModel> myCustomProfileEdit(Session session, String bio) async {
128+
final userProfile = await session.authenticated?.userProfile(session);
129+
130+
// Your custom logic here...
131+
132+
return userProfile;
133+
}
134+
}
135+
```
136+
71137
### Setting a default user image
72138

73139
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.

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,72 @@ await AuthServices.instance.userProfiles.changeFullName(session, authUserId, 'my
6868

6969
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.
7070

71+
### Accessing user profiles from the app
72+
73+
To access the user profile from your Flutter app, you can use the `userProfileInfo` endpoint that is included in the authentication module:
74+
75+
```dart
76+
final userProfile = await client.modules.serverpod_auth_core.userProfileInfo.get();
77+
```
78+
79+
This returns a `UserProfileModel` object containing the logged-in user's profile information such as their name, email, and profile picture.
80+
81+
### Extending the user profile edit endpoint
82+
83+
The authentication module provides a `UserProfileEditBaseEndpoint` abstract class that you can extend to expose user profile editing functionality to your app. This base endpoint includes methods for:
84+
85+
- Removing user images
86+
- Setting user images
87+
- Changing user names
88+
- Changing full names
89+
90+
To enable profile editing in your app, create a concrete endpoint class on your server by extending `UserProfileEditBaseEndpoint`:
91+
92+
```dart
93+
import 'package:serverpod/serverpod.dart';
94+
import 'package:serverpod_auth_idp_server/core.dart';
95+
96+
class UserProfileEditEndpoint extends UserProfileEditBaseEndpoint {}
97+
```
98+
99+
This endpoint will have both `get` (same as `userProfileInfo`) and all profile editing methods. You can then call these methods from your Flutter app:
100+
101+
```dart
102+
// Get the user's profile
103+
final profile = await client.userProfileEdit.get();
104+
105+
// Change the user's full name
106+
final updatedProfile = await client.userProfileEdit.changeFullName('John Doe');
107+
108+
// Change the user's username
109+
final updatedProfile = await client.userProfileEdit.changeUserName('johndoe');
110+
111+
// Remove the user's profile image
112+
final updatedProfile = await client.userProfileEdit.removeUserImage();
113+
114+
// Set a new profile image
115+
final ByteData imageData = // ... load image data
116+
final updatedProfile = await client.userProfileEdit.setUserImage(imageData);
117+
```
118+
119+
:::note
120+
The `UserProfileEditBaseEndpoint` requires authentication and operates on the currently authenticated user's profile.
121+
:::
122+
123+
You can also extend the endpoint class to add custom profile editing functionality:
124+
125+
```dart
126+
class UserProfileEditEndpoint extends UserProfileEditBaseEndpoint {
127+
Future<UserProfileModel> myCustomProfileEdit(Session session, String bio) async {
128+
final userProfile = await session.authenticated?.userProfile(session);
129+
130+
// Your custom logic here...
131+
132+
return userProfile;
133+
}
134+
}
135+
```
136+
71137
### Setting a default user image
72138

73139
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.

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,72 @@ await AuthServices.instance.userProfiles.changeFullName(session, authUserId, 'my
6868

6969
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.
7070

71+
### Accessing user profiles from the app
72+
73+
To access the user profile from your Flutter app, you can use the `userProfileInfo` endpoint that is included in the authentication module:
74+
75+
```dart
76+
final userProfile = await client.modules.serverpod_auth_core.userProfileInfo.get();
77+
```
78+
79+
This returns a `UserProfileModel` object containing the logged-in user's profile information such as their name, email, and profile picture.
80+
81+
### Extending the user profile edit endpoint
82+
83+
The authentication module provides a `UserProfileEditBaseEndpoint` abstract class that you can extend to expose user profile editing functionality to your app. This base endpoint includes methods for:
84+
85+
- Removing user images
86+
- Setting user images
87+
- Changing user names
88+
- Changing full names
89+
90+
To enable profile editing in your app, create a concrete endpoint class on your server by extending `UserProfileEditBaseEndpoint`:
91+
92+
```dart
93+
import 'package:serverpod/serverpod.dart';
94+
import 'package:serverpod_auth_idp_server/core.dart';
95+
96+
class UserProfileEditEndpoint extends UserProfileEditBaseEndpoint {}
97+
```
98+
99+
This endpoint will have both `get` (same as `userProfileInfo`) and all profile editing methods. You can then call these methods from your Flutter app:
100+
101+
```dart
102+
// Get the user's profile
103+
final profile = await client.userProfileEdit.get();
104+
105+
// Change the user's full name
106+
final updatedProfile = await client.userProfileEdit.changeFullName('John Doe');
107+
108+
// Change the user's username
109+
final updatedProfile = await client.userProfileEdit.changeUserName('johndoe');
110+
111+
// Remove the user's profile image
112+
final updatedProfile = await client.userProfileEdit.removeUserImage();
113+
114+
// Set a new profile image
115+
final ByteData imageData = // ... load image data
116+
final updatedProfile = await client.userProfileEdit.setUserImage(imageData);
117+
```
118+
119+
:::note
120+
The `UserProfileEditBaseEndpoint` requires authentication and operates on the currently authenticated user's profile.
121+
:::
122+
123+
You can also extend the endpoint class to add custom profile editing functionality:
124+
125+
```dart
126+
class UserProfileEditEndpoint extends UserProfileEditBaseEndpoint {
127+
Future<UserProfileModel> myCustomProfileEdit(Session session, String bio) async {
128+
final userProfile = await session.authenticated?.userProfile(session);
129+
130+
// Your custom logic here...
131+
132+
return userProfile;
133+
}
134+
}
135+
```
136+
71137
### Setting a default user image
72138

73139
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.

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,72 @@ await AuthServices.instance.userProfiles.changeFullName(session, authUserId, 'my
6868

6969
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.
7070

71+
### Accessing user profiles from the app
72+
73+
To access the user profile from your Flutter app, you can use the `userProfileInfo` endpoint that is included in the authentication module:
74+
75+
```dart
76+
final userProfile = await client.modules.serverpod_auth_core.userProfileInfo.get();
77+
```
78+
79+
This returns a `UserProfileModel` object containing the logged-in user's profile information such as their name, email, and profile picture.
80+
81+
### Extending the user profile edit endpoint
82+
83+
The authentication module provides a `UserProfileEditBaseEndpoint` abstract class that you can extend to expose user profile editing functionality to your app. This base endpoint includes methods for:
84+
85+
- Removing user images
86+
- Setting user images
87+
- Changing user names
88+
- Changing full names
89+
90+
To enable profile editing in your app, create a concrete endpoint class on your server by extending `UserProfileEditBaseEndpoint`:
91+
92+
```dart
93+
import 'package:serverpod/serverpod.dart';
94+
import 'package:serverpod_auth_idp_server/core.dart';
95+
96+
class UserProfileEditEndpoint extends UserProfileEditBaseEndpoint {}
97+
```
98+
99+
This endpoint will have both `get` (same as `userProfileInfo`) and all profile editing methods. You can then call these methods from your Flutter app:
100+
101+
```dart
102+
// Get the user's profile
103+
final profile = await client.userProfileEdit.get();
104+
105+
// Change the user's full name
106+
final updatedProfile = await client.userProfileEdit.changeFullName('John Doe');
107+
108+
// Change the user's username
109+
final updatedProfile = await client.userProfileEdit.changeUserName('johndoe');
110+
111+
// Remove the user's profile image
112+
final updatedProfile = await client.userProfileEdit.removeUserImage();
113+
114+
// Set a new profile image
115+
final ByteData imageData = // ... load image data
116+
final updatedProfile = await client.userProfileEdit.setUserImage(imageData);
117+
```
118+
119+
:::note
120+
The `UserProfileEditBaseEndpoint` requires authentication and operates on the currently authenticated user's profile.
121+
:::
122+
123+
You can also extend the endpoint class to add custom profile editing functionality:
124+
125+
```dart
126+
class UserProfileEditEndpoint extends UserProfileEditBaseEndpoint {
127+
Future<UserProfileModel> myCustomProfileEdit(Session session, String bio) async {
128+
final userProfile = await session.authenticated?.userProfile(session);
129+
130+
// Your custom logic here...
131+
132+
return userProfile;
133+
}
134+
}
135+
```
136+
71137
### Setting a default user image
72138

73139
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.

0 commit comments

Comments
 (0)