-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the Sign In, Sign Up with email & password and Facebook #176
Open
ajaman190
wants to merge
6
commits into
scorelab:master
Choose a base branch
from
ajaman190:v.0.71.x@auth
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7db6622
Fix login/sign with email & password
ajaman190 26c2bf3
Fix signin/signup with facebook
ajaman190 1df58e5
Update config.example file with firebase v9 config
ajaman190 b307f2f
Update readme for latest fbsdk config
ajaman190 8dfaab8
Updated config.example firebase to firebase compat mode
ajaman190 4b7f080
Updated all signin/signup firebase method to compat mode
ajaman190 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<resources> | ||
<string name="app_name">Go_social</string> | ||
<string name="facebook_app_id">2349388348405699</string> | ||
<string name="facebook_app_id">222891166977339</string> | ||
<string name="fb_login_protocol_scheme">fb1234</string> | ||
<string name="facebook_client_token">PLACE_YOUR_CLIENT_TOKEN_HERE</string> | ||
</resources> |
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,5 @@ | ||
export const fetchUserFbData = (token) => { | ||
return fetch( | ||
`https://graph.facebook.com/v2.8/me?fields=id,first_name,last_name,email,birthday&access_token=${token}` | ||
) | ||
} |
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 |
---|---|---|
|
@@ -9,132 +9,100 @@ import { | |
KeyboardAvoidingView, | ||
ScrollView, | ||
} from "react-native"; | ||
import { AccessToken, LoginManager } from "react-native-fbsdk"; | ||
import { f, auth } from "../../../config/config.js"; | ||
import { LoginManager, AccessToken } from "react-native-fbsdk-next"; | ||
import { app, auth, database } from "../../../config/config.js"; | ||
import {FacebookAuthProvider} from "firebase/auth"; | ||
import * as EmailValidator from "email-validator"; | ||
import styles from "./style"; | ||
import { SocialIcon } from "react-native-elements"; | ||
import styles from "./style"; | ||
import { fetchUserFbData } from "../../constants/auth.js"; | ||
|
||
export default class LoginScreen extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
email: "", | ||
Password: "", | ||
password: "", | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
var that = this; | ||
|
||
auth.onAuthStateChanged(function (user) { | ||
if (user) { | ||
that.redirectUser(); | ||
} | ||
}); | ||
} | ||
|
||
login() { | ||
let email = this.state.email; | ||
let password = this.state.Password; | ||
|
||
let { navigate } = this.props.navigation; | ||
|
||
auth | ||
.signInWithEmailAndPassword(email, password) | ||
.then(function (data) { | ||
navigate("App"); | ||
}) | ||
.catch(function (error) { | ||
var errorMessage = error.message; | ||
alert(errorMessage.toString()); | ||
}); | ||
} | ||
|
||
redirectUser() { | ||
const { navigate } = this.props.navigation; | ||
navigate("App"); | ||
} | ||
|
||
_signInAsync = async () => { | ||
if (EmailValidator.validate(this.state.email) === true) { | ||
if (this.state.Pasword != "") { | ||
// Validate the user's email and password | ||
async _signInAsync() { | ||
switch(true) { | ||
case !EmailValidator.validate(this.state.email): | ||
alert("Please enter a valid email!"); | ||
break; | ||
case this.state.password === "": | ||
alert("Enter your password!"); | ||
break; | ||
default: | ||
this.login(); | ||
} else { | ||
alert("Enter the password"); | ||
} | ||
} else { | ||
alert("Please enter A Valid Email"); | ||
break; | ||
} | ||
}; | ||
|
||
onPressLogin() { | ||
LoginManager.logInWithReadPermissions(["public_profile", "email"]).then( | ||
result => this._handleCallBack(result), | ||
function (error) { | ||
alert("Login fail with error: " + error); | ||
} | ||
); | ||
} | ||
|
||
_handleCallBack(result) { | ||
let _this = this; | ||
if (result.isCancelled) { | ||
alert("Login cancelled"); | ||
} else { | ||
AccessToken.getCurrentAccessToken().then(data => { | ||
const token = data.accessToken; | ||
fetch( | ||
"https://graph.facebook.com/v2.8/me?fields=id,first_name,last_name,gender,birthday&access_token=" + | ||
token | ||
) | ||
.then(response => response.json()) | ||
.then(json => { | ||
const imageSize = 120; | ||
const facebookID = json.id; | ||
const fbImage = `https://graph.facebook.com/${facebookID}/picture?height=${imageSize}`; | ||
this.authenticate(data.accessToken).then(function (result) { | ||
const { uid } = result; | ||
_this.createUser(uid, json, token, fbImage); | ||
}); | ||
}) | ||
.catch(function (err) { | ||
console.log(err); | ||
}); | ||
}); | ||
// Signin with email and password | ||
async login() { | ||
try { | ||
const email = this.state.email; | ||
const password = this.state.password; | ||
|
||
const res = await auth.signInWithEmailAndPassword(email, password); | ||
} catch (error) { | ||
alert(error.message.toString()); | ||
} | ||
} | ||
|
||
authenticate = token => { | ||
const provider = auth.FacebookAuthProvider; | ||
const credential = provider.credential(token); | ||
let ret = auth.signInWithCredential(credential); | ||
return ret; | ||
}; | ||
|
||
createUser = (uid, userData, token, dp) => { | ||
const defaults = { | ||
uid, | ||
token, | ||
dp, | ||
ageRange: [20, 30], | ||
}; | ||
f.database() | ||
.ref("users") | ||
.child(uid) | ||
.update({ ...userData, ...defaults }); | ||
}; | ||
|
||
_signInAsync = async () => { | ||
if (EmailValidator.validate(this.state.email) === true) { | ||
if (this.state.Pasword != "") { | ||
this.login(); | ||
} else { | ||
alert("Enter the password"); | ||
// Signin user with facebook account | ||
async _fbSignInAsync() { | ||
try { | ||
const result = await LoginManager.logInWithPermissions(["public_profile", "email"]); | ||
if (!result.isCancelled) { | ||
// Get the user's access token | ||
const data = await AccessToken.getCurrentAccessToken(); | ||
|
||
// Use the user's access token to authenticate with Firebase Authentication | ||
const credential = FacebookAuthProvider.credential(data.accessToken); | ||
const { user } = await auth.signInWithCredential(credential); | ||
|
||
const response = await fetchUserFbData(data.accessToken) | ||
const userData = await response.json(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So then we can remove await in here |
||
|
||
const photoURL = `https://graph.facebook.com/${userData.id}/picture?height=120`; | ||
this.createUser(user.uid, userData, data.accessToken, photoURL); | ||
} | ||
} else { | ||
alert("Please enter A Valid Email"); | ||
} catch (error) { | ||
alert(error.message.toString()); | ||
} | ||
}; | ||
} | ||
|
||
// Create user | ||
async createUser(uid, userData, token, photoURL) { | ||
try { | ||
const defaults = { uid, token, photoURL, Range: [20, 30] }; | ||
await database.ref(`users/${uid}`).set({ ...userData, ...defaults }); | ||
} catch (error) { | ||
alert(error.message.toString()); | ||
} | ||
} | ||
|
||
handleInput(input, text) { | ||
this.setState(prevState => ({ ...prevState, [input]: text })); | ||
} | ||
|
||
render() { | ||
return ( | ||
|
@@ -151,7 +119,7 @@ export default class LoginScreen extends Component { | |
keyboardType="email-address" | ||
placeholderTextColor="rgba(255,255,255,0.7)" | ||
style={styles.input} | ||
onChangeText={text => this.setState({ email: text })} | ||
onChangeText={text => this.handleInput("email", text)} | ||
ref={input => { | ||
this.textInput = input; | ||
}} | ||
|
@@ -161,24 +129,24 @@ export default class LoginScreen extends Component { | |
secureTextEntry={true} | ||
placeholderTextColor="rgba(255,255,255,0.7)" | ||
style={styles.input} | ||
onChangeText={text => this.setState({ Password: text })} | ||
onChangeText={text => this.handleInput("password", text)} | ||
ref={input => { | ||
this.textInput = input; | ||
}} | ||
/> | ||
</View> | ||
</KeyboardAvoidingView> | ||
<TouchableOpacity onPress={this._signInAsync} style={styles.loginButton}> | ||
<TouchableOpacity onPress={this._signInAsync.bind(this)} style={styles.loginButton}> | ||
<Text style={styles.buttonText}>Sign In</Text> | ||
</TouchableOpacity> | ||
|
||
<TouchableOpacity onPress={() => this.props.navigation.navigate("ForgotPassword")}> | ||
<Text style={styles.text}>Forgot Password?</Text> | ||
</TouchableOpacity> | ||
|
||
<TouchableOpacity onPress={this.onPressLogin.bind(this)}> | ||
<TouchableOpacity onPress={this._fbSignInAsync.bind(this)}> | ||
<SocialIcon | ||
style={{ width: 200 }} | ||
style={{ width: 290 }} | ||
title="Sign In With Facebook" | ||
button | ||
type="facebook" | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If these are configurations that should be configured by the developer, readme file should contain step by step guide to config this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added configuration in old readme file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please review the update reademe pr #169, so that i can also update this comfig in new readme file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address the issues in #169 first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, i will address this first
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this configuration, please review #169