Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
Update the function run by an event listener

I am working with Apple Social Sign On and need to run a function after a successful sign on. The function that gets run will change depending on where the user is in the app.

I declare an event listener:

   document.addEventListener("AppleIDSignInOnSuccess", (res) =>
     mode === "login"
       ? Apple.onSignInSuccess(res, callbacks, mode)
       : Apple.onVerifySuccess(res, callbacks)
   );

The issue I am having is that once this event listener is declared changing the value of the variable mode does not change the documents event listener.

Is there a way to update a documents event listeners?

The full class is defined as:

export class Apple {
    static init(callbacks, mode) {
        const AppleID = window.AppleID;
        const redirectURIBase = DEV ? "app-dev" : "app";
        const redirectURI = `https://${redirectURIBase}.sandboxx.us/profile`;

        document.addEventListener("AppleIDSignInOnFailure", (err) =>
            Apple.onSignInFailure(err, callbacks)
        );
        document.addEventListener("AppleIDSignInOnSuccess", (res) =>
            mode === "login"
                ? Apple.onSignInSuccess(res, callbacks, mode)
                : Apple.onVerifySuccess(res, callbacks)
        );
        AppleID.auth.init({
            clientId: "com.sandboxx.web",
            scope: "name email",
            redirectURI,
            usePopup: true,
        });
    }
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!