Step 4: Write Login and Logout Functions

On the web page, provide a login and optional logout JavaScript function in the body to handle onLogin and onLogout events. With these functions, you determine what happens when users log in and out successfully. You have full control over what happens.

Warning
Warning In Summer ’24, Salesforce made Embedded Login disabled by default. We recommend that you use the web server flow, the user-agent flow, or another redirect-based OAuth 2.0 flow instead of Embedded Login.

Embedded Login relies on third-party cookies, which are blocked or restricted in most browsers. And Embedded Login works only on Google Chrome and only as long as third-party cookies are allowed there by default.

  1. Add a login function to the body of the web page.
  2. Optionally, add code to the login function to retrieve user information from Salesforce.
  3. Optionally, add a logout function to the body of the web page.