Skip to content

Commit ca5f899

Browse files
authored
Merge pull request #50 from nvh95/2.x
2.x PLAN
2 parents 522ccb4 + 0d89c3c commit ca5f899

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+35840
-27630
lines changed

.babelrc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"env": {
3+
"test": {
4+
"presets": [["@babel/preset-env"], "@babel/preset-react"]
5+
}
6+
},
7+
"presets": [
8+
[
9+
"@babel/preset-env",
10+
{
11+
"modules": false
12+
}
13+
],
14+
"@babel/preset-react"
15+
],
16+
"ignore": ["node_modules/**"],
17+
"plugins": ["@babel/plugin-transform-runtime"]
18+
}

.eslintrc.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// .eslintrc
2+
module.exports = {
3+
parser: '@typescript-eslint/parser',
4+
ignorePatterns: ['.eslintrc.js'],
5+
parserOptions: {
6+
ecmaVersion: 12,
7+
sourceType: 'module',
8+
},
9+
plugins: ['@typescript-eslint'],
10+
extends: [
11+
'eslint:recommended',
12+
'plugin:@typescript-eslint/recommended',
13+
'prettier',
14+
'plugin:react-hooks/recommended',
15+
],
16+
17+
rules: {
18+
'@typescript-eslint/no-unused-vars': 'error',
19+
},
20+
21+
env: {
22+
browser: true,
23+
es2021: true,
24+
},
25+
};

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
npm-debug.log*
88
.DS_Store
99
.netlify
10-
.npmrc
10+
.npmrc
11+
/build

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
es
2+
lib
3+
node_modules

.prettierrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"bracketSpacing": true,
5+
"tabWidth": 2
6+
}

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"editor.defaultFormatter": "esbenp.prettier-vscode",
3+
"editor.formatOnSave": true,
4+
"files.insertFinalNewline": true,
5+
"editor.formatOnPaste": false,
6+
"cSpell.words": ["emailaddress"]
7+
}

CHANGELOG.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,44 @@
1+
## 2.x
2+
3+
### Features
4+
5+
[Pull Request](https://github.com/nvh95/react-linkedin-login-oauth2/pull/50)
6+
7+
- Rewritten in typescript
8+
- Use functional component
9+
- Use rollup
10+
- Fix bugs on Next.js
11+
- Drop IE support
12+
- Drop default UI
13+
- Bring back `state` parameter (optional, randomly generate `state` by default)
14+
15+
## 1.0.10
16+
17+
### Features
18+
19+
- Support React ^17.x
20+
121
## 1.0.9
22+
223
### Features
24+
325
- Remove prop `state`. It's generated automatically
426
- Add `style` prop
27+
528
### Fixes
29+
630
- Remove `index.css` to fix #13, #30
731

832
### Chores
33+
934
- Remove default class `btn-linkedin`
1035
- Inline button style. (TODO: To use children as renderElement in 2.x)
1136
- Update README to use image from `react-linkedin-login-oauth2/assets/linkedin.png`
1237

13-
1438
## 1.0.8
1539

1640
### Fixes
41+
1742
- Make `scope` to be a required property with default value of `r_emailaddress`
1843
- Make the pop up center of the screen
1944
- Update demo link in README.md
@@ -22,9 +47,11 @@
2247
### 1.0.7
2348

2449
### Features
50+
2551
- Be able to render custom element (Thank @YBeck for your contribution)
2652
- Support IE11, please see #support-ie in README.md for more detail
2753
- Check `state` to avoid CSRF attack
2854

2955
### Fixes
30-
- Remove unnecessary `console.log`
56+
57+
- Remove unnecessary `console.log`

MIGRATION-from-1-to-2.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
### MIGRATION TO VERSION 2
2+
3+
`react-linkedin-login-oauth2` is rewritten using typescript and updated to use functional component with hooks. The API also changed to make it easier to integrate. In version 1, it comes with a default `Signin with Linked In` button. In version 2, you can use your own `Signin with Linked In` button. You cans still use the default image, which is bundled within the package at `react-linkedin-login-oauth2/assets/linkedin.png`.
4+
5+
- The `onSuccess` callback now have `code` as an argument (version 1 is `{code}`)
6+
- The callback to handle error changed name from `onFailure` to `onError`
7+
8+
Given that in version 1, your code is similar to bellow:
9+
10+
```javascript
11+
import { LinkedIn } from 'react-linkedin-login-oauth2';
12+
13+
function LoginWithLinked() {
14+
const handleSuccess = (data) => {
15+
console.log(data.code);
16+
};
17+
const handleFailure = (error) => {
18+
console.log(error.errorMessage);
19+
};
20+
return (
21+
<LinkedIn
22+
clientId="your-client-id"
23+
onSuccess={handleSuccess}
24+
onFailure={handleFailure}
25+
redirectUri="http://localhost:3000/linkedin"
26+
renderElement={({ onClick, disabled }) => (
27+
<button onClick={onClick} disabled={disabled}>
28+
Signin with Linkedin
29+
</button>
30+
)}
31+
/>
32+
);
33+
}
34+
```
35+
36+
In version 2, you can use it with hooks like this:
37+
38+
```javascript
39+
import { useLinkedIn } from 'react-linkedin-login-oauth2';
40+
// You can still use default image provided by the package
41+
import linkedin from 'react-linkedin-login-oauth2/assets/linkedin.png';
42+
43+
function LoginWithLinked() {
44+
const { linkedInLogin } = useLinkedIn({
45+
clientId: 'your-client-id',
46+
redirectUri: 'http://localhost:3000/linkedin',
47+
onSuccess: (code) => {
48+
// Change from `data.code` to `code`
49+
console.log(code);
50+
},
51+
// Change from `onFailure` to `onError`
52+
onError: (error) => {
53+
console.log(error);
54+
},
55+
});
56+
57+
return (
58+
<img
59+
src={linkedin}
60+
alt="Log in with Linked In"
61+
style={{ maxWidth: '180px' }}
62+
// Pass `linkedInLogin` to `onClick` handler
63+
onClick={linkedInLogin}
64+
/>
65+
);
66+
}
67+
```
68+
69+
If you do not like hooks, you can use render props:
70+
71+
```diff
72+
import { LinkedIn } from 'react-linkedin-login-oauth2';
73+
74+
function LoginWithLinked() {
75+
const handleSuccess = (data) => {
76+
console.log(data.code);
77+
};
78+
const handleFailure = (error) => {
79+
console.log(error.errorMessage);
80+
};
81+
return (
82+
<LinkedIn
83+
clientId="your-client-id"
84+
onSuccess={handleSuccess}
85+
onFailure={handleFailure}
86+
redirectUri="http://localhost:3000/linkedin"
87+
- renderElement={({ onClick, disabled }) => (
88+
- <button onClick={onClick} disabled={disabled}>
89+
+ >
90+
+ {({ linkedInLogin }) => (
91+
+ <button onClick={linkedInLogin}>
92+
Signin with Linkedin
93+
</button>
94+
)}
95+
- />
96+
+ </LinkedIn>
97+
);
98+
}
99+
```

0 commit comments

Comments
 (0)