-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
616004f
commit 3f9398b
Showing
5 changed files
with
216 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// import {Platform} from 'react-native'; | ||
// import { | ||
// appleAuth, | ||
// appleAuthAndroid, | ||
// } from '@invertase/react-native-apple-authentication'; | ||
// import jwt_decode from 'jwt-decode'; | ||
// import {loadString, saveString} from '@utils'; | ||
export {}; | ||
// import {randomUniqueId} from '../string/index'; | ||
|
||
// async function pickInfoAppleResponse(info: any = {}, appleId: string) { | ||
// try { | ||
// const infoCache = await loadString(appleId); | ||
|
||
// const infoName = infoCache ? infoCache : info; | ||
// let userFullName = `${infoName?.familyName?.trim?.() || ''}${ | ||
// infoName?.namePrefix || '' | ||
// } ${infoName?.middleName || ''} ${infoName?.givenName || ''}`?.trim(); | ||
|
||
// if (!userFullName) { | ||
// userFullName = `${infoName?.firstName || ''} ${ | ||
// infoName?.lastName || '' | ||
// }`.trim(); | ||
// } | ||
|
||
// if (!Object.keys(infoCache || {})?.length) { | ||
// saveString(appleId, JSON.stringify(info)); | ||
// } | ||
|
||
// return userFullName; | ||
// } catch { | ||
// return undefined; | ||
// } | ||
// } | ||
|
||
// export const AppleService = { | ||
// appleSignin: async () => { | ||
// if (Platform.OS === 'ios') { | ||
// try { | ||
// const appleAuthRequestResponse = await appleAuth.performRequest({ | ||
// requestedOperation: appleAuth.Operation.LOGIN, | ||
// requestedScopes: [appleAuth.Scope.EMAIL, appleAuth.Scope.FULL_NAME], | ||
// }); | ||
|
||
// const userFullName = await pickInfoAppleResponse( | ||
// appleAuthRequestResponse.fullName, | ||
// appleAuthRequestResponse.user, | ||
// ); | ||
|
||
// return {...appleAuthRequestResponse, userFullName}; | ||
// } catch (err) { | ||
// console.log('IOS-APPPLE-LOGIN-ERROR', err); | ||
// } | ||
// } else { | ||
// try { | ||
// // Generate secure, random values for state and nonce | ||
// const rawNonce = randomUniqueId(); | ||
// const state = randomUniqueId(); | ||
|
||
// // Configure the request | ||
// appleAuthAndroid.configure({ | ||
// // The Service ID you registered with Apple | ||
// clientId: 'CLIENT_ID_APPLE_SERVICE', | ||
|
||
// // Return URL added to your Apple dev console. We intercept this redirect, but it must still match | ||
// // the URL you provided to Apple. It can be an empty route on your backend as it's never called. | ||
// redirectUri: 'APPLE_REDIRECT_URI', | ||
|
||
// // The type of response requested - code, id_token, or both. | ||
// responseType: appleAuthAndroid.ResponseType.ALL, | ||
|
||
// // The amount of user information requested from Apple. | ||
// scope: appleAuthAndroid.Scope.ALL, | ||
|
||
// // Random nonce value that will be SHA256 hashed before sending to Apple. | ||
// nonce: rawNonce, | ||
|
||
// // Unique state value used to prevent CSRF attacks. A UUID will be generated if nothing is provided. | ||
// state, | ||
// }); | ||
|
||
// // Open the browser window for user sign in | ||
// const response = await appleAuthAndroid.signIn(); | ||
// const infoLogin = { | ||
// ...response, | ||
// ...(jwt_decode(response.id_token || '') as any), | ||
// }; | ||
|
||
// const appleId = infoLogin.sub; | ||
// const {nonce} = infoLogin; | ||
// const identityToken = response.id_token || ''; | ||
// // apple return full name one times. so save full name util push to BE successfully | ||
// const userFullName = await pickInfoAppleResponse( | ||
// response.user?.name, | ||
// appleId, | ||
// ); | ||
|
||
// return {user: appleId, nonce, identityToken, userFullName}; | ||
// // Send the authorization code to your backend for verification | ||
// } catch (err) { | ||
// console.log('ANDROID-APPPLE-LOGIN-ERROR', err); | ||
// } | ||
// } | ||
// }, | ||
// }; |
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// import { | ||
// AccessToken, | ||
// GraphRequest, | ||
// GraphRequestManager, | ||
// LoginManager, | ||
// Settings, | ||
// } from 'react-native-fbsdk-next'; | ||
export {}; | ||
// const init = () => { | ||
// Settings.initializeSDK(); | ||
// }; | ||
|
||
// type LoginResult = {success: boolean; token?: string}; | ||
// const login = () => { | ||
// return new Promise<LoginResult>(rs => { | ||
// LoginManager.logInWithPermissions(['public_profile', 'email']).then( | ||
// result => { | ||
// if (result.isCancelled) { | ||
// rs({success: false}); | ||
// } else { | ||
// AccessToken.getCurrentAccessToken() | ||
// .then(data => { | ||
// if (data && data.accessToken) { | ||
// rs({success: true, token: data.accessToken}); | ||
// } else { | ||
// rs({success: false}); | ||
// } | ||
// }) | ||
// .catch(err => { | ||
// console.log('FACEBOOK-LOGIN-ERROR', err); | ||
// rs({success: false}); | ||
// }); | ||
// } | ||
// }, | ||
// ); | ||
// }); | ||
// }; | ||
|
||
// const logout = async () => { | ||
// try { | ||
// const data = await AccessToken.getCurrentAccessToken(); | ||
// if (data?.accessToken) { | ||
// const logoutGraph = new GraphRequest( | ||
// 'me/permissions/', | ||
// { | ||
// accessToken: data?.accessToken, | ||
// httpMethod: 'DELETE', | ||
// }, | ||
// error => { | ||
// if (error) { | ||
// console.log('Error fetching data: ' + error.toString()); | ||
// } else { | ||
// LoginManager.logOut(); | ||
// } | ||
// }, | ||
// ); | ||
// new GraphRequestManager().addRequest(logoutGraph).start(); | ||
// } else { | ||
// LoginManager.logOut(); | ||
// } | ||
// } catch (err) { | ||
// console.log('FACEBOOK-LOGOUT-ERROR', err); | ||
// } | ||
// }; | ||
|
||
// export const FacebookService = { | ||
// init, | ||
// login, | ||
// logout, | ||
// }; |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// import {GoogleSignin} from '@react-native-google-signin/google-signin'; | ||
|
||
// const init = () => { | ||
// GoogleSignin.configure(); | ||
// }; | ||
export {}; | ||
// type LoginResult = {success: boolean; token?: string}; | ||
// const login = async (): Promise<LoginResult> => { | ||
// try { | ||
// await GoogleSignin.hasPlayServices(); | ||
// await GoogleSignin.signIn(); | ||
// const userToken = await GoogleSignin.getTokens(); | ||
// return {success: true, token: userToken.accessToken}; | ||
// } catch (err) { | ||
// console.log('GOOGLE-LOGIN-ERROR', err); | ||
// return {success: false}; | ||
// } | ||
// }; | ||
|
||
// const logout = async () => { | ||
// try { | ||
// await GoogleSignin.signOut(); | ||
// return true; | ||
// } catch (err) { | ||
// console.log('GOOGLE-LOGOUT-ERROR', err); | ||
// } | ||
// }; | ||
|
||
// export const GoogleService = { | ||
// init, | ||
// login, | ||
// logout, | ||
// }; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './apple'; | ||
export * from './facebook'; | ||
export * from './google'; |