• JMap.User.loginIntoOrganization

    When using the new oAuth2 authentication setup, will redirect the user to the identity provider and be redirected back. The method resolves with nothing.

    When using the legacy REST API-based authentication method, it sets and returns Session Data specific to a JMap Cloud organization. You need to be previously authenticated via the JMap.User.login method before calling this method.

    This method can also be used to switch between organizations while a user is already logged in.

    Parameters

    • organizationId: string

    Returns Promise<JSessionData> | Promise<void>

    Throws

    Error if user is not authenticated

    Example

    const userLogin = "jdo@mycompany.com"
    const userPassword = "xxx"

    // Open a new user session in a REST API-based authentication setup, and get back user data from server
    JMap.User
    .login(userLogin, userPassword)
    .then(sessionData => {
    console.log(`User ${userLogin} has been authenticated, will login to one of it's organization`)
    if(sessionData.organizationInfos.length === 0){
    console.error("User has no organization")
    }else{
    const organizationInfo = sessionData.organizationInfos[sessionData.organizationInfos.length - 1]
    JMap.User
    .loginIntoOrganization(organizationInfo.id)
    .then(sessionData2=>{
    console.log(`User ${userLogin} has been logged into organization "${sessionData2.currentOrganization.name}", his session token is "${sessionData2.accessToken}"`)
    })
    }
    })
    .catch(error => {
    console.error(`Cannot loggin ${userLogin}, error: `, error)
    })