Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to modify post data while calling login service? #151

Open
nikhil-ahuja opened this issue Jan 3, 2017 · 1 comment
Open

How to modify post data while calling login service? #151

nikhil-ahuja opened this issue Jan 3, 2017 · 1 comment

Comments

@nikhil-ahuja
Copy link

I want to make a Login API call which accept following parameters:

{ "action":"login",
"data":{
"username": "[email protected]",
"password":"123456"
}
}

I want to pass such data to onFormSubmit callback of LoginPage and want to set the headers as well.

headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
}

How can I pass post data with headers in Login API call?

Please give an example for that.

@the-overengineer
Copy link

As for passing custom headers from the login form, the SDK currently does not support this. However, the Accept header will automatically be set to application/json, and the Content-Type will be set to application/json as well, when talking to one of the Stormpath back-end integrations.

As for formatting the custom data, you can do it like this:

onSubmit(event, next) {
  const data = {
    action: 'login',
    data: event.data // event.data contains username and password fields by default
  };

  // next (err, data)
  next(null, data);
}
// If defined, onSubmit will be called before handing anything over to the API
<LoginForm onSubmit={this.onSubmit.bind(this)} />

@robertjd Maybe we should add an example of this in the example app?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants