score:12
Accepted answer
you can use a custom callback to return json data.
app.post('/api/auth/login', function(req, res, next) {
passport.authenticate('local-login', function(error, user, info) {
if(error) {
return res.status(500).json(error);
}
if(!user) {
return res.status(401).json(info.message);
}
res.json(user);
})(req, res, next);
});
Source: stackoverflow.com
Related Query
- React + Redux: "<Provider> does not support changing `store` on the fly"
- Does the passport.js support ajax?
- Does Amplify SDK support PKCE out of the box for your React site?
- useState does not support a second callBack, what could be the easy fix?
- Why does setState callback throw an error: "State updates from the useState() and useReducer() Hooks don't support the second callback argument..."
- ReactKonva does not support the type "div"
- Why does calling react setState method not mutate the state immediately?
- What does the error "JSX element type '...' does not have any construct or call signatures" mean?
- Does React keep the order for state updates?
- In React ES6, why does the input field lose focus after typing a character?
- Support for the experimental syntax 'classProperties' isn't currently enabled
- Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema
- Why do the React docs recommend doing AJAX in componentDidMount, not componentWillMount?
- Support for the experimental syntax 'jsx' isn't currently enabled
- How do I restrict the type of React Children in TypeScript, using the newly added support in TypeScript 2.3?
- What does the at symbol (@) do in ES6 javascript? (ECMAScript 2015)
- error TS2602: JSX element implicitly has type 'any' because the global type 'JSX.Element' does not exist
- What does the hook numbers in the Reactjs Dev tool correspond to?
- Why does the Airbnb style guide say that relying on function name inference is discouraged?
- Error: Cannot find file: 'index.js' does not match the corresponding name on disk: './node_modules/React/react'
- What does the CssBaseline class do?
- React wrapper: React does not recognize the `staticContext` prop on a DOM element
- How to solve Warning: React does not recognize the X prop on a DOM element
- Babel throwing Support for the experimental syntax 'jsx' isn't currently enabled
- React props: Should I pass the object or its properties? Does it make much difference?
- When you run jest --coverage, what does the Branches column do/mean?
- does react really need nodeJS on the frontend ENV?
- How to wait for AJAX response and only after that render the component?
- How to fix the "Warning: useLayoutEffect does nothing on the server"?
- Does react-router support relative links?
More Query from same tag
- Uncaught TypeError: Cannot read property 'value' of null in ReactJS
- State set to true is returning false
- api data fetching best practice in react
- Array key does not get interpolated when making object
- React unique "key" error
- React router 4 HashRouter, how do I hide hash in the url?
- Checkbox value reversed in setState
- Apollo Client Async Refresh Token
- Struggle with typing redux-form component
- How to map an object's keys to make JSON easier to handle in React
- Material UI Autocomplete - unchecking checkboxes in renderOption using Redux dispatch
- Cannot find module 'file-name.png' or its corresponding type declarations - typescript react
- TypeError: Cannot destructure property 'setValues' of 'Object(...)(...)' as it is undefined. (react / create-react-app)
- Why mapStateToProps return empty object when state has been mutated?
- How to always initialise prop of this reactjs component?
- Conditional Rendering through a function is always False
- In Redux-saga, how to get a result from a yield call to a Promise?
- Resize highcharts using react-grid-layout not working
- Render not worked in react
- How to better setup fetch with useEffect?
- Adding resolver to React-router
- React useEffect cleanup function unexpectedly called
- Reactjs slider(carousel) with multiple slides in a page
- Props are not passing from parent to child components in React Functional component
- How to recursively pass up all data from form?
- How to automatically add appropriate class name to the React elements
- How do you use the Swiper callback methods in React?
- What is the name option in react-testing-library?
- Custom back navigation for reactnavigation back button
- How to set BackgroundImage full page in ReactJS?