-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathUserLinkExamples.cs
53 lines (49 loc) · 1.91 KB
/
UserLinkExamples.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Threading.Tasks;
using MongoDB.Bson;
using Realms.Sync;
namespace Examples
{
public class UserLinkExamples
{
App app;
public async Task LinksAUser()
{
app = App.Create("");
{
// :snippet-start: link
// 1) A user logs on anonymously:
var anonUser = await app.LogInAsync(Credentials.Anonymous());
// 2) They create some data, and then decide they want to save
// it, which requires creating an Email/Password account.
// 3) We prompt the user to log in, and then use that info to
// register the new EmailPassword user, and then generate an
// EmailPassword credential to link the existing anonymous
// account:
var email = "caleb@example.com";
var password = "shhhItsASektrit!";
await app.EmailPasswordAuth.RegisterUserAsync(
email, password);
var officialUser = await anonUser.LinkCredentialsAsync(
Credentials.EmailPassword(email, password));
// :snippet-end:
}
{
// :snippet-start: link2
var anonUser = await app.LogInAsync(Credentials.Anonymous());
var officialUser = await anonUser.LinkCredentialsAsync(
Credentials.Google("<google-token>", GoogleCredentialType.AuthCode));
// :snippet-end:
}
return;
}
public async Task ReadUserProfile()
{
// :snippet-start: user-metadata
var user = await app.LogInAsync(
Credentials.EmailPassword("user1@example.com", "p@ssw0rd"));
Console.WriteLine($"The user's email is {user.Profile.Email}");
// :snippet-end:
}
}
}