forked from mongodb/docs-realm
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
8c8747a
commit bfa3fb8
Showing
20 changed files
with
606 additions
and
539 deletions.
There are no files selected for viewing
415 changes: 229 additions & 186 deletions
415
...s/kotlin/shared/src/commonTest/kotlin/com/mongodb/realm/realmkmmapp/AuthenticationTest.kt
Large diffs are not rendered by default.
Oops, something went wrong.
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
1 change: 0 additions & 1 deletion
1
source/examples/generated/kotlin/AuthenticationTest.snippet.access-token-refresh.kt
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
// Gets the current refresh token for the user | ||
fun getRefreshToken(): String { | ||
return user.refreshToken | ||
} |
12 changes: 5 additions & 7 deletions
12
...es/generated/kotlin/AuthenticationTest.snippet.anonymous-authentication-reuse-existing.kt
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 |
---|---|---|
@@ -1,8 +1,6 @@ | ||
runBlocking { | ||
// Logs in with anonymous user | ||
val anonUser = app.login(Credentials.anonymous()) | ||
// Logs in with an anonymous user | ||
val anonUser = app.login(Credentials.anonymous()) | ||
|
||
// Creates a new anonymous user | ||
val otherAnonUser = | ||
app.login(Credentials.anonymous(reuseExisting = false)) | ||
} | ||
// Logs in with a new, different anonymous user | ||
val otherAnonUser = | ||
app.login(Credentials.anonymous(reuseExisting = false)) |
5 changes: 3 additions & 2 deletions
5
source/examples/generated/kotlin/AuthenticationTest.snippet.anonymous-authentication.kt
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
val app: App = App.create(YOUR_APP_ID) // Replace this with your App ID | ||
runBlocking { // use runBlocking sparingly -- it can delay UI interactions | ||
val user = app.login(Credentials.anonymous()) | ||
runBlocking { | ||
val anonymousCredentials = Credentials.anonymous() | ||
val user = app.login(anonymousCredentials) | ||
} |
2 changes: 1 addition & 1 deletion
2
source/examples/generated/kotlin/AuthenticationTest.snippet.api-key-authentication.kt
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
val app: App = App.create(YOUR_APP_ID) // Replace this with your App ID | ||
runBlocking { // use runBlocking sparingly -- it can delay UI interactions | ||
runBlocking { | ||
val user = app.login(Credentials.apiKey(key)) | ||
} |
6 changes: 4 additions & 2 deletions
6
source/examples/generated/kotlin/AuthenticationTest.snippet.apple-authentication.kt
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
val app: App = App.create(YOUR_APP_ID) // Replace this with your App ID | ||
runBlocking { // use runBlocking sparingly -- it can delay UI interactions | ||
val user = app.login(Credentials.apple(idToken)) | ||
runBlocking { | ||
// Registration is handled by Apple | ||
val appleCredentials = Credentials.apple(idToken) | ||
val user = app.login(appleCredentials) | ||
} |
13 changes: 7 additions & 6 deletions
13
source/examples/generated/kotlin/AuthenticationTest.snippet.auth-change-listener.kt
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
// Create a Flow of AuthenticationChange objects | ||
app.authenticationChangeAsFlow().collect() { change: AuthenticationChange -> | ||
when (change) { | ||
is LoggedIn -> proceedToAppActivity(change.user) | ||
is LoggedOut -> proceedToLoginActivity(change.user) | ||
is Removed -> proceedToRemovedUserActivity(change.user) | ||
} | ||
app.authenticationChangeAsFlow().collect { | ||
change: AuthenticationChange -> | ||
when (change) { | ||
is LoggedIn -> proceedToAppActivity(change.user) | ||
is LoggedOut -> proceedToLoginActivity(change.user) | ||
is Removed -> proceedToRemovedUserActivity(change.user) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
source/examples/generated/kotlin/AuthenticationTest.snippet.create-new-user.kt
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,10 @@ | ||
// Instantiate your App Services App | ||
val app = App.create(YOUR_APP_ID) // Replace this with your App ID | ||
runBlocking { | ||
// Log in the user with the credentials associated | ||
// with the authentication provider | ||
// If successful, returns an authenticated `User` object | ||
val user = app.login(credentials) | ||
|
||
// ... work with the user ... | ||
} |
5 changes: 2 additions & 3 deletions
5
...ce/examples/generated/kotlin/AuthenticationTest.snippet.custom-function-authentication.kt
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
// Create custom arguments for your Atlas Function | ||
val customCredentials = Credentials.customFunction( | ||
payload = mapOf("username" to "bob") | ||
) | ||
|
||
// Pass the generated credential to app.login() | ||
val currentUser = app.login(customCredentials) | ||
val user = app.login(customCredentials) |
5 changes: 3 additions & 2 deletions
5
source/examples/generated/kotlin/AuthenticationTest.snippet.email-password-authentication.kt
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
val app: App = App.create(YOUR_APP_ID) // Replace this with your App ID | ||
runBlocking { // use runBlocking sparingly -- it can delay UI interactions | ||
val user = app.login(Credentials.emailPassword(email, password)) | ||
runBlocking { | ||
val emailPasswordCredentials = Credentials.emailPassword(email, password) | ||
val user = app.login(emailPasswordCredentials) | ||
} |
6 changes: 4 additions & 2 deletions
6
source/examples/generated/kotlin/AuthenticationTest.snippet.jwt-authentication.kt
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
val app: App = App.create(YOUR_APP_ID) // Replace this with your App ID | ||
runBlocking { // use runBlocking sparingly -- it can delay UI interactions | ||
val user = app.login(Credentials.jwt(jwtToken)) | ||
runBlocking { | ||
// Registration is handled by the JWT provider | ||
val jwtCredentials = Credentials.jwt(jwtToken) | ||
val user = app.login(jwtCredentials) | ||
} |
4 changes: 2 additions & 2 deletions
4
source/examples/generated/kotlin/AuthenticationTest.snippet.link-credentials.kt
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
val app: App = App.create(YOUR_APP_ID) // Replace this with your App ID | ||
runBlocking { // use runBlocking sparingly -- it can delay UI interactions | ||
runBlocking { | ||
val user = app.login(Credentials.anonymous()) // logs in with an anonymous user | ||
// registers an email/password user | ||
app.emailPasswordAuth.registerUser(email, password) | ||
// links anonymous user with email/password credentials | ||
user.linkCredentials(Credentials.emailPassword(email, password)); | ||
user.linkCredentials(Credentials.emailPassword(email, password)) | ||
} |
6 changes: 3 additions & 3 deletions
6
source/examples/generated/kotlin/AuthenticationTest.snippet.log-out.kt
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
val app: App = App.create(YOUR_APP_ID) // Replace this with your App ID | ||
runBlocking { | ||
// Log user in | ||
val user = app.login(credentials) | ||
|
||
// Work with logged-in user ... | ||
// ... work with logged-in user ... | ||
|
||
// Log user out | ||
// Ensure all local updates are uploaded | ||
// before logging out | ||
user.logOut() | ||
} |
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
Oops, something went wrong.