Redux JWT 身份验证示例 这是一个 React 和 Redux 应用中如何实现 JWT 身份验证的示例。它使用了 Auth0 的 NodeJS JWT 服务。
Redux JWT 身份验证示例 这是一个 React 和 Redux 应用中如何实现 JWT 身份验证的示例。它使用了 Auth0 的 NodeJS JWT 服务。
This is a sample of how to implement JWT authentication in React and Redux apps. It uses Auth0's NodeJS JWT Authentication Sample to authenticate users and retrieve quotes from a protected endpoint.
The sample is well-informed by the official Redux examples.
Check the auth0-lock branch for the Auth0 specific version
Clone the repo and run the installation commands, each in a new terminal window.
# Get the server submodule
git submodule update --init
# Install deps in the project root and in the server directory
npm install
cd server && npm install
cd ..
# Run the server
npm run server
# New terminal window
npm startThe app will be served at localhost:3000.
Users are authenticated by making a fetch request to localhost:3001/sessions/create. We have actions setup for this.
…We also have actions for retreiving the quotes that uses an API middleware.
…// actions.js
// Uses the API middlware to get a quote
export function fetchQuote() {
return {
[CALL_API]: {
endpoint: 'random-quote',
types: [QUOTE_REQUEST, QUOTE_SUCCESS, QUOTE_FAILURE]
}
}
}
// Same API middlware is used to get a
// secret quote, but we set authenticated
// to true so that the auth header is sent
export function fetchSecretQuote() {
return {
[CALL_API]: {
endpoint: 'protected/random-quote',
authenticated: true,
types: [QUOTE_REQUEST, QUOTE_SUCCESS, QUOTE_FAILURE]
}
}
}The reducers return new objects with the data carried by the actions.
…Auth0 helps you to:
If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.
This project is licensed under the MIT license. See the LICENSE file for more info.
暂无开放 Issues,或尚未同步最近议题。