generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 39
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 #203 from Real-Dev-Squad/SignInWithGithub
SignInWithGithub
- Loading branch information
Showing
10 changed files
with
151 additions
and
117 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
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 |
---|---|---|
@@ -1,5 +1,56 @@ | ||
const githubConfig = { | ||
clientId: '23c78f66ab7964e5ef97', | ||
import AsyncStorage from '@react-native-async-storage/async-storage'; | ||
|
||
export const clientId = '23c78f66ab7964e5ef97'; | ||
export const clientSecret = '65621db87076180ab274b6dbdc1a3dd95b9dd952'; | ||
export const redirectUri = 'app://deeplink'; | ||
export const tokenUrl = 'https://github.com/login/oauth/access_token'; | ||
|
||
const githubConfig = async (authorizationCode) => { | ||
// Make POST request and handle response as previously explained | ||
console.log('response in github config', authorizationCode); | ||
|
||
const response = await fetch(tokenUrl, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Accept: 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
client_id: clientId, | ||
client_secret: clientSecret, | ||
code: authorizationCode, | ||
redirect_uri: redirectUri, | ||
}), | ||
}); | ||
console.log('response in github config', response); | ||
|
||
if (response.ok) { | ||
console.log('response is the res ok?'); | ||
|
||
const data = await response.json(); | ||
const accessToken = data.access_token; | ||
|
||
// Call a function to securely store the access token | ||
storeAccessTokenSecurely(accessToken); | ||
} else { | ||
// Handle error response | ||
console.log('error'); | ||
console.error( | ||
'Error exchanging code for access token:', | ||
response.status, | ||
response.statusText, | ||
); | ||
} | ||
}; | ||
|
||
const storeAccessTokenSecurely = async (accessToken) => { | ||
console.log('access token', accessToken); | ||
try { | ||
// Store the access token in a secure storage | ||
await AsyncStorage.setItem('access_token', accessToken); | ||
console.log('Access token stored securely.'); | ||
} catch (error) { | ||
console.error('Error storing access token:', error); | ||
} | ||
}; | ||
export { githubConfig }; |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
const AuthApis = { | ||
USER_DETAIL: 'https://api.realdevsquad.com/users/userId/', | ||
QR_AUTH_API: 'https://api.realdevsquad.com/auth/qr-code-auth', | ||
GITHUB_AUTH_API: 'https://api.realdevsquad.com/auth/github/login', | ||
}; | ||
|
||
export default AuthApis; |
Oops, something went wrong.