-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[docs] Add info on using AuthSession with Firebase #8185
Comments
Concerns with the following approach:
Just an update, I recently tested Firebase Google auth with
My completed code looked like: import {
makeRedirectUri,
ResponseType,
useAuthRequest,
useAutoDiscovery,
} from "expo-auth-session";
import * as WebBrowser from "expo-web-browser";
import firebase from "firebase";
import React from "react";
import { Button, Platform, StyleSheet, View } from "react-native";
WebBrowser.maybeCompleteAuthSession();
if (!firebase.apps.length) {
// Your web app's Firebase configuration
const firebaseConfig = {
/* Config */
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
}
export default function App() {
const useProxy = Platform.select({ web: false, default: true });
const discovery = useAutoDiscovery("https://accounts.google.com");
// Request
const [request, response, promptAsync] = useAuthRequest(
{
clientId: Platform.select({
web:
"Your-Web-Client-ID.apps.googleusercontent.com",
default: "you do not have this yet"
}),
redirectUri: makeRedirectUri({
// For usage in bare and standalone
native:
"you do not have this yet",
useProxy,
}),
usePKCE: false,
responseType: ResponseType.Token,
scopes: ["openid", "profile"],
},
discovery
);
React.useEffect(() => {
firebase.auth().onAuthStateChanged((user) => {
console.log("USER: ", user);
});
}, []);
React.useEffect(() => {
if (response && response.type === "success") {
const credential = new firebase.auth.GoogleAuthProvider.credential(
null, // Pass the access_token as the second property
response.params.access_token
);
firebase.auth().signInWithCredential(credential);
}
}, [response]);
return (
<View style={styles.container}>
<Button
disabled={!request}
onPress={() => promptAsync({ useProxy })}
title="Login"
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
}); Pressing the button (on web first) should open the popup and give you an error:
Return to your app, pressing "Login" should now work as expected. |
Cite https://firebase.google.com/docs/auth/web/facebook-login#expandable-2-label import firebase from 'firebase';
// Later in functional component
const [, result, prompt] = useAuthRequest();
// Later in effect...
const credential = firebase.auth.FacebookAuthProvider.credential(result.params.access_token);
// Sign in with the credential from the Facebook user.
firebase.auth().signInWithCredential(credential) GithubCite https://firebase.google.com/docs/auth/web/github-auth#expandable-1-label const credential = firebase.auth.GithubAuthProvider.credential(access_token); FitBitand all second-class firebase auth providers. Cite: https://firebase.google.com/docs/auth/web/custom-auth#authenticate-with-firebase firebase.auth().signInWithCustomToken(access_token).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// ...
}); |
Hi @EvanBacon does the useProxy work for you? I and several others have found it not working in the latest version. Several of us have posted issues in the forums with no responses yet. |
Closing as this is more-or-less implemented |
It's not entirely clear how to use existing auth methods with Firebase. We should document how to do it!
From my outdated Github + Firebase auth guide:
Related: https://twitter.com/childishludino/status/1258106926333857794?s=20
The text was updated successfully, but these errors were encountered: