https://github.com/mzxyz/react-native-jwt
This library provides JSON web token parser for React-Native
https://github.com/mzxyz/react-native-jwt
jwt react-native
Last synced: 2 months ago
JSON representation
This library provides JSON web token parser for React-Native
- Host: GitHub
- URL: https://github.com/mzxyz/react-native-jwt
- Owner: mzxyz
- Created: 2019-03-17T23:03:22.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-19T01:39:17.000Z (over 7 years ago)
- Last Synced: 2026-03-22T22:36:35.117Z (3 months ago)
- Topics: jwt, react-native
- Language: Objective-C
- Size: 11.7 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# react-native-jwt-utils
This library provides JSON web token parser for React-Native. Only support `HS256` `HS384` `HS512` algorithm currently.
## Getting started
`$ npm install react-native-jwt-utils --save`
### Mostly automatic installation
`$ react-native link react-native-jwt-utils`
### Manual installation
#### iOS
1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [react-native-jwt-utils]`
2. Go to `node_modules` ➜ `react-native-jwt-utils` and add `RNJWT.xcodeproj`
3. In XCode, in the project navigator, select your project. Add `libRNJWT.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`
4. Run your project (`Cmd+R`)<
#### Android
1. Open up `android/app/src/main/java/[...]/MainActivity.java`
- Add `import com.reactlibrary.RNJWTPackage;` to the imports at the top of the file
- Add `new RNJWTPackage()` to the list returned by the `getPackages()` method
2. Append the following lines to `android/settings.gradle`:
```
include ':react-native-jwt-utils'
project(':react-native-jwt-utils').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-jwt-utils/android')
```
3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
```
compile project(':react-native-jwt-utils')
```
## Usage
```javascript
import { verify } from 'react-native-jwt-utils';
const key = 'sf42t3g42g33rfsef24';
const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.ighoTHFH7ZhkCMjX0JIMVrGTawxm7-eZf5U8TDIuNY8';
verify(token, key)
.then(decodedToken => ...)
.catch(e => ...);
```