Sending Successful Form Submission
If you configured sending successful form submission on the dashboard, and you're using the JS SDK (cotter or cotter-react), you can add the following to your success function:
`cotter` JS SDK
`cotter-react` React SDK
1
​
2
import Cotter, { CotterEnum } from 'cotter';
3
​
4
var cotterApiKeyID = "<YOUR_API_KEY_ID>"
5
var cotter = new Cotter(cotterApiKeyID); // πŸ‘ˆ Specify your API KEY ID here
6
var formID = "form_default"
7
cotter
8
.withFormID(formID) // Use customization for form "form_default"
9
.signInWithLink() // Sign In with Magic Link
10
.showPhoneForm() // Send Magic Link via Phone Number
11
.then((resp) => {
12
13
// ==
14
// RUN SUCCESSFUL FORM SUBMISSION
15
// SETUP THAT YOU HAVE IN THE DASHBOARD
16
// ==
17
fetch(`${CotterEnum.WorkerURL}/completion/form?form-id=${encodeURIComponent(formID)}`,{
18
method: "POST",
19
headers: {
20
API_KEY_ID: cotterApiKeyID,
21
"Content-type": "application/json",
22
},
23
body: JSON.stringify(resp),
24
}).then((_) => {
25
window.location.href = "/protected";// redirect to the protected page
26
})
27
// ==
28
29
})
30
.catch(err => {
31
console.log(err) // handle error
32
});
Copied!
1
import { LoginForm } from "cotter-react";
2
import { CotterEnum } from 'cotter';
3
//...
4
​
5
const onSuccess = (resp) => {
6
// ==
7
// RUN SUCCESSFUL FORM SUBMISSION
8
// SETUP THAT YOU HAVE IN THE DASHBOARD
9
// ==
10
fetch(`${CotterEnum.WorkerURL}/completion/form?form-id=${encodeURIComponent(formID)}`,{
11
method: "POST",
12
headers: {
13
API_KEY_ID: cotterApiKeyID,
14
"Content-type": "application/json",
15
},
16
body: JSON.stringify(resp),
17
}).then((_) => {
18
window.location.href = "/protected";// redirect to the protected page
19
})
20
// ==
21
}
22
​
23
//...
24
<LoginForm
25
type="EMAIL" // - EMAIL or PHONE
26
authMethod="MAGIC_LINK" // - OTP or MAGIC_LINK
27
onSuccess={onSuccess} // - A function that runs after the login/signup is successful
28
onError={(err) => console.log(err)} // - A function that runs if the login/signup encountered an error
29
width={340} // - Width & height of the form
30
height={300} // Recommended at least 300x300
31
formID={"form_default"}
32
/>
Copied!
​
Last modified 6mo ago
Copy link