Skip to content

Commit

Permalink
bugfix: fix login method to work on native
Browse files Browse the repository at this point in the history
  • Loading branch information
hyochan committed Sep 10, 2022
1 parent 69af6f3 commit 5d477b4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-native-seoul/kakao-login",
"version": "5.1.0",
"version": "5.1.1",
"description": "React Native Module for Kakao Login",
"main": "src/index.js",
"types": "src/index.d.ts",
Expand Down
38 changes: 20 additions & 18 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,29 +70,31 @@ export type KakaoProfileWebType = {
export const login = async (
props?: KaKaoLoginWebType,
): Promise<KakaoOAuthWebToken | KakaoOAuthToken> => {
if (!props) {
throw new Error('Web parameters are not provided');
}
try {
if (Platform.OS === 'web') {
if (!props) {
throw new Error('Web parameters are not provided');
}

const {restApiKeyWeb, redirectUrlWeb, codeWeb} = props;
const {restApiKeyWeb, redirectUrlWeb, codeWeb} = props;

if (!restApiKeyWeb || !redirectUrlWeb || !codeWeb) {
throw new Error('Web parameters are not provided');
}
if (!restApiKeyWeb || !redirectUrlWeb || !codeWeb) {
throw new Error('Web parameters are not provided');
}

const data: any = {
grant_type: 'authorization_code',
client_id: restApiKeyWeb,
redirect_uri: redirectUrlWeb,
code: codeWeb,
};
const data: any = {
grant_type: 'authorization_code',
client_id: restApiKeyWeb,
redirect_uri: redirectUrlWeb,
code: codeWeb,
};

const queryString = Object.keys(data)
.map((k: any) => encodeURIComponent(k) + '=' + encodeURIComponent(data[k]))
.join('&');
const queryString = Object.keys(data)
.map(
(k: any) => encodeURIComponent(k) + '=' + encodeURIComponent(data[k]),
)
.join('&');

try {
if (Platform.OS === 'web') {
const result = await fetch('https://kauth.kakao.com/oauth/token', {
method: 'post',
body: queryString,
Expand Down

0 comments on commit 5d477b4

Please sign in to comment.