-
Notifications
You must be signed in to change notification settings - Fork 88
(DOCSP-27598): Clean up web auth examples #2640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
78382f1
5c9615d
af04cdb
0f6e4ac
fce6aee
a6b06c4
ac665b7
ff94ca5
52bc404
bad2201
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,12 @@ | ||
async function loginAnonymous() { | ||
// Create an anonymous credential | ||
const credentials = Realm.Credentials.anonymous(); | ||
try { | ||
// Authenticate the user | ||
const user = await app.logIn(credentials); | ||
// `App.currentUser` updates to match the logged in user | ||
console.assert(user.id === app.currentUser.id); | ||
return user; | ||
} catch (err) { | ||
console.error("Failed to log in", err); | ||
} | ||
|
||
// Authenticate the user | ||
const user = await app.logIn(credentials); | ||
// `App.currentUser` updates to match the logged in user | ||
console.assert(user.id === app.currentUser.id); | ||
|
||
return user; | ||
} | ||
const user = await loginAnonymous(); | ||
console.log("Successfully logged in!", user.id); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
async function loginApiKey(apiKey) { | ||
// Create an API Key credential | ||
const credentials = Realm.Credentials.apiKey(apiKey); | ||
try { | ||
// Authenticate the user | ||
const user = await app.logIn(credentials); | ||
// `App.currentUser` updates to match the logged in user | ||
console.assert(user.id === app.currentUser.id); | ||
return user; | ||
} catch (err) { | ||
console.error("Failed to log in", err); | ||
} | ||
|
||
// Authenticate the user | ||
const user = await app.logIn(credentials); | ||
|
||
// `App.currentUser` updates to match the logged in user | ||
console.assert(user.id === app.currentUser.id); | ||
|
||
return user; | ||
} | ||
|
||
const user = await loginApiKey(REALM_API_KEY.key); // add previously generated API key | ||
console.log("Successfully logged in!", user); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
// Get the ID token from the Apple SDK | ||
AppleID.auth | ||
.signIn() | ||
.then(({ id_token }) => { | ||
// Define credentials with the ID token from the Apple SDK | ||
const credentials = Realm.Credentials.apple(id_token); | ||
// Log the user in to your app | ||
return app.logIn(credentials); | ||
}) | ||
.then((user) => { | ||
console.log(`Logged in with id: ${user.id}`); | ||
}); | ||
const { id_token } = await AppleID.auth.signIn(); | ||
|
||
// Define credentials with the ID token from the Apple SDK | ||
const credentials = Realm.Credentials.apple(id_token); | ||
|
||
// Log the user in to your app | ||
const user = await app.logIn(credentials); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// When the user is redirected back to your app, handle the redirect to | ||
// save the user's access token and close the redirect window. This | ||
// returns focus to the original application window and automatically | ||
// logs the user in. | ||
Realm.handleAuthRedirect(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,8 @@ const redirectUri = "https://app.example.com/handleOAuthLogin"; | |
const credentials = Realm.Credentials.apple(redirectUri); | ||
|
||
// Calling logIn() opens an Apple authentication screen in a new window. | ||
app.logIn(credentials).then((user) => { | ||
// The logIn() promise will not resolve until you call `handleAuthRedirect()` | ||
// from the new window after the user has successfully authenticated. | ||
console.log(`Logged in with id: ${user.id}`); | ||
}); | ||
const user = app.logIn(credentials); | ||
|
||
// When the user is redirected back to your app, handle the redirect to | ||
// save the user's access token and close the redirect window. This | ||
// returns focus to the original application window and automatically | ||
// logs the user in. | ||
Realm.handleAuthRedirect(); | ||
// The logIn() promise will not resolve until you call `Realm.handleAuthRedirect()` | ||
// from the new window after the user has successfully authenticated. | ||
console.log(`Logged in with id: ${user.id}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we split this into two code snippets? It's not totally clear to the skimmer that Also, we have the same codeblock for Facebook but an entirely different format for Google. Should we unify these? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i thought about doing that in the first pass but didn't b/c of fact it was pretty outside scope of original ticket + some laziness. but we already got outside the scope of the ticket so might as well go for it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and in the spirit of scope creep, i think i'll just throw in https://jira.mongodb.org/browse/DOCSP-28363 w this ticket as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// When the user is redirected back to your app, handle the redirect to | ||
// save the user's access token and close the redirect window. This | ||
// returns focus to the original application window and automatically | ||
// logs the user in. | ||
Realm.handleAuthRedirect(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,12 @@ | ||
async function loginCustomFunction(payload) { | ||
// Create a Custom Function credential | ||
const credentials = Realm.Credentials.function(payload); | ||
try { | ||
// Authenticate the user | ||
const user = await app.logIn(credentials); | ||
// `App.currentUser` updates to match the logged in user | ||
console.assert(user.id === app.currentUser.id); | ||
return user; | ||
} catch (err) { | ||
console.error("Failed to log in", err); | ||
} | ||
|
||
// Authenticate the user | ||
const user = await app.logIn(credentials); | ||
// `App.currentUser` updates to match the logged in user | ||
console.assert(user.id === app.currentUser.id); | ||
|
||
return user; | ||
} | ||
loginCustomFunction({ username: "ilovemongodb" }).then((user) => { | ||
console.log("Successfully logged in!", user); | ||
}); | ||
const user = await loginCustomFunction({ username: "ilovemongodb" }); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,12 @@ | ||
async function loginCustomJwt(jwt) { | ||
// Create a Custom JWT credential | ||
const credentials = Realm.Credentials.jwt(jwt); | ||
try { | ||
// Authenticate the user | ||
const user = await app.logIn(credentials); | ||
// `App.currentUser` updates to match the logged in user | ||
console.assert(user.id === app.currentUser.id); | ||
return user; | ||
} catch (err) { | ||
console.error("Failed to log in", err); | ||
} | ||
|
||
// Authenticate the user | ||
const user = await app.logIn(credentials); | ||
// `App.currentUser` updates to match the logged in user | ||
console.assert(user.id === app.currentUser.id); | ||
|
||
return user; | ||
} | ||
loginCustomJwt("eyJ0eXAi...Q3NJmnU8oP3YkZ8").then((user) => { | ||
console.log("Successfully logged in!", user); | ||
}); | ||
const user = await loginCustomJwt("eyJ0eXAi...Q3NJmnU8oP3YkZ8"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
async function loginEmailPassword(email, password) { | ||
// Create an email/password credential | ||
const credentials = Realm.Credentials.emailPassword(email, password); | ||
try { | ||
// Authenticate the user | ||
const user = await app.logIn(credentials); | ||
// `App.currentUser` updates to match the logged in user | ||
console.assert(user.id === app.currentUser.id); | ||
return user; | ||
} catch (err) { | ||
console.error("Failed to log in", err); | ||
} | ||
|
||
// Authenticate the user | ||
const user = await app.logIn(credentials); | ||
// `App.currentUser` updates to match the logged in user | ||
console.assert(user.id === app.currentUser.id); | ||
|
||
return user; | ||
} | ||
|
||
const user = await loginEmailPassword("[email protected]", "passw0rd"); | ||
console.log("Successfully logged in!", user); |
Uh oh!
There was an error while loading. Please reload this page.