colossal-appointment-48082
06/22/2023, 6:42 PMbreezy-evening-56597
salmon-night-88354
06/22/2023, 7:26 PMsalmon-night-88354
06/22/2023, 7:26 PMsalmon-night-88354
06/22/2023, 7:32 PMsalmon-night-88354
06/22/2023, 7:38 PM// Extract user information from the query in you application - below data is a sample
// Args:
// user: user meta data for signup.
const user = {"name": "Joe Person", "phone": "+15555555555", "email": "<mailto:email@company.com|email@company.com>"}
// identifier: email or phone - becomes the externalID for the user from here on and also used for delivery
const identifier = "<mailto:chris@descope.com|chris@descope.com>"
// uri: this is the link that user is sent (code appended) for verification. Your application needs to host
// this page and extract the token for verification. The token arrives as a query parameter named 't'
const verify_uri = "<http://auth.company.com/api/verify_enchantedlink>"
// Return value:
// resp - json object containing ref_token and linkId.
// ref_token - this is a reference that is used for polling till you get a valid session.
// See the polling section.
// linkId - this is the number that you must show to the user on the screen which matches
// to one of the link sent in email.
var pendingRef = ""
var resp = await mySdk.enchantedLink.signUpOrIn(identifier, verify_uri);
if (!resp.ok) {
console.log("Failed to initialize signUpOrIn flow")
console.log("Status Code: " + resp.code)
console.log("Error Code: " + resp.error.errorCode)
console.log("Error Description: " + resp.error.errorDescription)
console.log("Error Message: " + resp.error.message)
}
else {
console.log("Successfully initialized signUpOrIn flow")
const linkIdentifier = resp.data.linkId;
console.log("linkId " + linkIdentifier)
pendingRef = resp.data.pendingRef;
console.log("pendingRef " + pendingRef)
}
var resp = await mySdk.enchantedLink.waitForSession(pendingRef);
if (!resp.ok) {
console.log("Failed to initialize polling flow")
console.log("Status Code: " + resp.code)
console.log("Error Code: " + resp.error.errorCode)
console.log("Error Description: " + resp.error.errorDescription)
console.log("Error Message: " + resp.error.message)
}
else {
console.log("Successfully completed polling flow")
console.log(resp)
}
Then on click, your verify page will do the following:
const token = "5d45e3f3ea48f95d0825fb19169c41369fa50db987b7670bfa8aa127908468eb"
const resp = await mySdk.enchantedLink.verify(token);
console.log(resp)
if (!resp.ok) {
console.log("Failed to verify enchanted link")
console.log("Status Code: " + resp.code)
console.log("Error Code: " + resp.error.errorCode)
console.log("Error Description: " + resp.error.errorDescription)
console.log("Error Message: " + resp.error.message)
}
else {
console.log("Successfully verified enchanted link")
console.log(resp)
}
Fo ex here I gave the wrong token. It fails verification, but the polling session has no response to show since no successful session was found.great-diamond-35515
06/22/2023, 7:56 PMcolossal-appointment-48082
06/22/2023, 8:27 PM