There was a TypeError encountered because 'undefined' is not able to be evaluated as an object when trying to execute '_ExponentFacebook.default.initializeAsync'

I am encountering a TypeError while attempting to implement Facebook Auth in my firebase react native project, specifically at the InitalizeAsync method.

import * as Facebook from 'expo-facebook';

export const loginWithFacebook = async () => {
  await Facebook.initializeAsync('ID_OF_APP');
  const {type, token}: any = await Facebook.logInWithReadPermissionsAsync({
    permissions: ['public_profile', 'email'],
  });

I have been troubleshooting this issue for the past day with no success so far.

Note that ID_OF_APP is mentioned here only for illustration purposes and is not my actual code.

Answer №1

Give this approach a try

import { AccessToken, LoginManager } from "react-native-fbsdk"

        state = {
                email: '',
                sso_token: '',
                sso_uid: '',
                loading: false,
            }    

authenticateUser(token) {
    axios({
        method: 'GET',
        url: `https://graph.facebook.com/v2.5/me?fields=email,name,friends&access_token=${token}`,
        responseType: 'json'
    }).then((response) => {

        const { data } = response

        const { first_name, last_name } = this.split_name(data.name)

        this.setState(
            { sso_token: token, sso_uid: data.id, email: data.email, first_name, last_name },
        )
    }).catch((err) => { console.warn(err) })
}

 onFacebookSignIn() {
    this.setState({ loading: true })

    LoginManager.logInWithPermissions(["email", "public_profile"])
        .then(result => {
            if (result.isCancelled) {
                this.setState({ loading: false })
            }
            else {
                AccessToken.getCurrentAccessToken()
                    .then((data) => {
                        const { accessToken } = data
                        this.authenticateUser(accessToken)
                    })
                    .catch((error) => {
                        console.warn(error)
                    })
            }
        })
        .catch(error => {
            console.warn(error)
            this.setState({ loading: false })
        }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the process for uploading an image using react native?

When uploading an image with React JS, the process looks like this: const onSubmit = (e) => { console.log(e.img); form.append("file", e.img.originFileObj); Axios.post("url", form, { headers: { Authorization ...

You cannot employ typed arguments in combination with Typescript within the VueJS framework

I'm struggling to develop a typescript vue component with some methods. Here is the script snippet. <script lang="ts"> import Vue from 'vue'; export default Vue.extend({ methods: { check(value: number) { console.log(valu ...

Having trouble with Jest imports not functioning as expected when using ts-jest

Currently, I am utilizing Jest in conjunction with ts-jest to conduct tests on my TypeScript code. Everything is functioning well except for the issue that arises when importing external libraries. Strangely enough, while import dotenv from 'dotenv&ap ...

You are unable to modify a read-only property of an Object in TypeScript

Could someone please elucidate why and how this situation could arise? In my typescript application, I am utilizing Zustand state management. Within the app, I update specific elements by extracting them from the state and using a simple Object.assign to ...

Trustpilot: The function window.Trustpilot.loadFromElement does not exist in Safari

I am looking to integrate 3 TrustPilots into my Angular application. import { Component, Input, OnInit } from '@angular/core'; declare global { interface Window { Trustpilot: any; } } window.Trustpilot = window.Trustpilot || {}; @Component ...

Create an error handling mechanism that intercepts errors using the displayed information

During my training, I am in the process of creating a small Angular application. One of the tasks I am working on involves implementing an error interceptor based on the guidelines provided in the Angular tutorial. The main goal is to effectively handle er ...

Clicking on components that are stacked on top of each

I am facing an issue with two React arrow function components stacked on top of each other using absolute positioning. Both components have onClick attributes, but I want only the one on top to be clickable. Is there a workaround for this? Here is a simpl ...

Refreshing Angular 4 Checkboxes: A Step-by-Step Guide

I am facing an issue with a checkbox bound to an array of type Interface. The Interface looks like this: export interface IdataTypes { Categories: string, isSelected: boolean, } This is how it is bound: <div *ngFor="let DT ...

TSLint is unable to locate a custom module containing a custom d.ts file

I've been searching for a solution to this issue, but haven't found a definitive answer yet. My current challenge involves using the suncalc module with TypeScript. Since it doesn't come with its own typing file, I created one and saved it ...

Filtering a list of invoices to find those including a "TV" item within its nested item list can be achieved efficiently using TypeScript

I am working with an array of "Invoices" objects that contain a nested array of "Items". Here is an example: [ { "invoiceNo":"10", "customerId":"101", "invoiceTotal":"2500", "items":[ { "itemId":"1", ...

What is the TypeScript definition for the return type of a Reselect function in Redux?

Has anyone been able to specify the return type of the createSelector function in Redux's Reselect library? I didn't find any information on this in the official documentation: https://github.com/reduxjs/reselect#q-are-there-typescript-typings ...

Switch the ngClass on the appropriate ancestor element for the dropdown menu

Utilizing Angular CLI version 8.3.0, I aim to construct a sidebar featuring a drop-down menu. My objective is to apply the "open" class to toggle the opening of the drop-down section. However, the current challenge I am encountering is that when I click to ...

Troubleshooting TypeScript import problems within apollo-server-express, apollo-server, and apollo-cache-control

Currently, I am in the process of upgrading from "apollo-server": "^2.9.4" and "apollo-server-express": "^2.9.4 to version 2.12.0 in my Typescript project. However, while building the application, I encountered the following error: node_modules/apollo ...

Scroll to reach the bottom of the page triggers an activation function

I need help figuring out how to trigger a function when the scrollbar reaches the bottom of the page. Is there a way to determine if the scroll has reached the end of the page? @HostListener("window:scroll", []) onScroll(): void { if ((window.innerHeight ...

In app.component.ts, the Transloco translateService.translate function is failing to function properly

I have encountered an issue where when I put the following code in my app.component.ts constructor, it does not work: alert(this.translateService.translate('navigation.dashboard')); But interestingly, if I place the same code in a submodule, it ...

Hermes js engine encounters a TypeError when attempting to access the property '__expo_module_name__' of an undefined value

After updating my expo and react native app to the latest version, I encountered a problem that I couldn't find a solution for despite searching on Google. Link to image ...

Displaying search results in various Angular components

On my home page (homePageComponent), I have a search feature. When the user clicks on the search button, they are redirected to a different page called the search list page (searchListComponent). Within the searchListComponent, there is another component c ...

Can we define the input and return types for functions using httpsCallables?

I have implemented a callable function in my app to update user claims. The functions are written in Typescript and I have used an interface to define the required data shape for the function. My objective is to make it easier for any developer on the tea ...

Fill out FormBuilder using data from a service within Angular2

I am working with an Angular2 model that I'm filling with data from a service. My goal is to use this model to update a form (created using FormBuilder) so that users can easily edit the information. Although my current approach works, I encounter er ...

Expo app experiencing issues with the @react-three/fiber node module

I'm encountering an issue with my expo app. All the modules are in JavaScript, but I am now trying to incorporate @react-three/fiber, which is written in TypeScript. It seems like the module isn't functioning properly because Expo isn't comp ...