-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from zonayedpca/v0.8.0-beta
V0.8.0 beta
- Loading branch information
Showing
7 changed files
with
177 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ branches: | |
|
||
platform: | ||
- x64 | ||
# - x86 | ||
|
||
cache: | ||
- node_modules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,124 +1,128 @@ | ||
import axios from 'axios'; | ||
|
||
import { | ||
TOKEN_RIGHT, | ||
TOKEN_WRONG, | ||
TOKEN_RESET, | ||
TOKEN_LOADING | ||
} from './type'; | ||
import { TOKEN_RIGHT, TOKEN_WRONG, TOKEN_RESET, TOKEN_LOADING } from './type'; | ||
|
||
import { getLocalStorageData, setLocalStorageData, unSetLocalStorageData } from '../utils'; | ||
import { | ||
getLocalStorageData, | ||
setLocalStorageData, | ||
unSetLocalStorageData, | ||
} from '../utils'; | ||
|
||
const GITHUB_LINK = `https://api.github.com`; | ||
const BITLY_LINK = `https://api-ssl.bitly.com/v4`; | ||
|
||
export const getLocalAuth = () => { | ||
const [github_token, bitly_token] = getLocalStorageData(['github', 'bitly']); | ||
return dispatch => { | ||
if(github_token) { | ||
dispatch({ | ||
type: TOKEN_RIGHT, | ||
payload: { | ||
name: 'github', | ||
token: github_token.token | ||
const [github_token, bitly_token] = getLocalStorageData([ | ||
'github', | ||
'bitly', | ||
]); | ||
return dispatch => { | ||
if (github_token) { | ||
dispatch({ | ||
type: TOKEN_RIGHT, | ||
payload: { | ||
name: 'github', | ||
token: github_token.token, | ||
}, | ||
}); | ||
} | ||
}); | ||
} | ||
if(bitly_token) { | ||
dispatch({ | ||
type: TOKEN_RIGHT, | ||
payload: { | ||
name: 'bitly', | ||
token: { | ||
token: bitly_token.token.token, | ||
id: bitly_token.token.id | ||
} | ||
if (bitly_token) { | ||
dispatch({ | ||
type: TOKEN_RIGHT, | ||
payload: { | ||
name: 'bitly', | ||
token: { | ||
token: bitly_token.token.token, | ||
id: bitly_token.token.id, | ||
}, | ||
}, | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
|
||
export const verifyGithubToken = token => { | ||
return async dispatch => { | ||
dispatch({ | ||
type: TOKEN_LOADING, | ||
payload: { | ||
name: 'github' | ||
} | ||
}); | ||
try { | ||
const { data } = await axios(`${GITHUB_LINK}/gists`, { | ||
headers: { | ||
Authorization: `Bearer ${token}` | ||
} | ||
}); | ||
if(data.length) { | ||
return async dispatch => { | ||
dispatch({ | ||
type: TOKEN_RIGHT, | ||
payload: { | ||
name: 'github', | ||
token | ||
} | ||
type: TOKEN_LOADING, | ||
payload: { | ||
name: 'github', | ||
}, | ||
}); | ||
setLocalStorageData('github', { token }); | ||
} | ||
} catch (e) { | ||
dispatch({ | ||
type: TOKEN_WRONG, | ||
payload: { | ||
name: 'github', | ||
error: true | ||
try { | ||
const { data } = await axios(`${GITHUB_LINK}/user`, { | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}); | ||
if (data.login) { | ||
dispatch({ | ||
type: TOKEN_RIGHT, | ||
payload: { | ||
name: 'github', | ||
token, | ||
}, | ||
}); | ||
setLocalStorageData('github', { token }); | ||
} | ||
} catch (e) { | ||
dispatch({ | ||
type: TOKEN_WRONG, | ||
payload: { | ||
name: 'github', | ||
error: true, | ||
}, | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
|
||
export const verifyBitlyToken = token => { | ||
return async dispatch => { | ||
dispatch({ | ||
type: TOKEN_LOADING, | ||
payload: { | ||
name: 'bitly' | ||
} | ||
}); | ||
try { | ||
const { data } = await axios(`${BITLY_LINK}/user`, { | ||
headers: { | ||
Authorization: `Bearer ${token}` | ||
} | ||
}); | ||
if(data.login) { | ||
return async dispatch => { | ||
dispatch({ | ||
type: TOKEN_RIGHT, | ||
payload: { | ||
name: 'bitly', | ||
token: { | ||
token, | ||
id: data.default_group_guid | ||
} | ||
} | ||
type: TOKEN_LOADING, | ||
payload: { | ||
name: 'bitly', | ||
}, | ||
}); | ||
setLocalStorageData('bitly', { token: { token, id: data.default_group_guid } }); | ||
} | ||
} catch (e) { | ||
dispatch({ | ||
type: TOKEN_WRONG, | ||
payload: { | ||
name: 'bitly', | ||
error: true | ||
try { | ||
const { data } = await axios(`${BITLY_LINK}/user`, { | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}); | ||
if (data.login) { | ||
dispatch({ | ||
type: TOKEN_RIGHT, | ||
payload: { | ||
name: 'bitly', | ||
token: { | ||
token, | ||
id: data.default_group_guid, | ||
}, | ||
}, | ||
}); | ||
setLocalStorageData('bitly', { | ||
token: { token, id: data.default_group_guid }, | ||
}); | ||
} | ||
} catch (e) { | ||
dispatch({ | ||
type: TOKEN_WRONG, | ||
payload: { | ||
name: 'bitly', | ||
error: true, | ||
}, | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
|
||
export const resetTokens = () => { | ||
return dispatch => { | ||
dispatch({ | ||
type: TOKEN_RESET | ||
}); | ||
unSetLocalStorageData(['github', 'bitly']); | ||
} | ||
} | ||
return dispatch => { | ||
dispatch({ | ||
type: TOKEN_RESET, | ||
}); | ||
unSetLocalStorageData(['github', 'bitly']); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.