def login()

in modular-service-cli/modular_service_cli/group/modularservice.py [0:0]


def login(ctx: ContextObj, username: str, password: str, **kwargs):
    """
    Authenticates user to work with Modular API.
    """
    resp = ctx.api_client.login(username=username, password=password)
    if resp.exc or not resp.ok:
        return resp
    # check_version_compatibility(resp.api_version)

    ctx.config.access_token = resp.data['access_token']
    if rt := resp.data.get('refresh_token'):
        ctx.config.refresh_token = rt
    resp.data = {'message': 'Logged in successfully'}
    # if rt := resp.data.get('refresh_token'):
    #     ctx['config'].refresh_token = rt
    return resp