Skip to content

request.auth == null even if user is authenticated (firestore) #4996

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

Closed
Tommertom opened this issue Jun 8, 2021 · 4 comments
Closed

request.auth == null even if user is authenticated (firestore) #4996

Tommertom opened this issue Jun 8, 2021 · 4 comments

Comments

@Tommertom
Copy link

Tommertom commented Jun 8, 2021

Hi,

I like to open a ticket related to the error message reported in #1491

Error in console.log:

FirebaseError: Missing or insufficient permissions.
    at new e (prebuilt-109c6673-0f51e182.js:188)
    at prebuilt-109c6673-0f51e182.js:10416
    at prebuilt-109c6673-0f51e182.js:10417
    at e.onMessage (prebuilt-109c6673-0f51e182.js:10439)
    at prebuilt-109c6673-0f51e182.js:10356
    at prebuilt-109c6673-0f51e182.js:10387
    at prebuilt-109c6673-0f51e182.js:15194
    at ZoneDelegate.invoke (zone.js:400)
    at Zone.run (zone.js:160)
    at zone.js:1318

Running
NodeJS : v14.16.0 (C:\Program Files\nodejs\node.exe)
npm : 7.6.3
OS : Windows 10

Chrome Version 91.0.4472.77 (Official Build) (64-bit)
Firebase Auth, Firestore

Versions in cli:

      "firebase": "^8.6.5",
     "@angular/fire": "^6.1.5",

Getting above mentioned error trying to access data in firestore - using a simple starter app to access data in firestore

Firestore rules:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
        allow read, write: if request.auth!=null;
    }
  }
}

High level flow - user authentication using Facebook login (via Firebase) and then a simple query on a collection in the store.

If I change the rules to say:
allow read,write: if true; or
allow read,write: if request.auth==null;
all works fine. If I transplant the angular code of this small project into a copy of a production app, the code works fine (full swap contents of src folder): after login, the query delivers the requested data.

With these two experiments I assume to have demonstrated an issue with the dependencies related to angular, angularfire and or the firebase sdk - most likely firebase given the things mentioned in #1491 and the fact that angualar/angularfire only wraps the firebase js sdk. But I could be wrong of course.

package.json for the project which gives errors:

{
    "name": "k2",
    "version": "0.0.1",
    "author": "Ionic Framework",
    "homepage": "https://ionicframework.com/",
    "scripts": {
        "dev": "ionic serve -w chrome --ssl",
        "deploy": "ionic build --prod &&  firebase deploy --only hosting",
        "ng": "ng",
        "start": "ng serve",
        "build": "ng build",
        "test": "ng test",
        "lint": "ng lint",
        "e2e": "ng e2e"
    },
    "private": true,
    "dependencies": {
        "@angular/common": "~12.0.1",
        "@angular/core": "~12.0.1",
        "@angular/fire": "^6.1.5",
        "@angular/forms": "~12.0.1",
        "@angular/platform-browser": "~12.0.1",
        "@angular/platform-browser-dynamic": "~12.0.1",
        "@angular/router": "~12.0.1",
        "@capacitor/cli": "^3.0.0",
        "@capacitor/core": "^3.0.0",
        "@ionic/angular": "^5.5.2",
        "@ngneat/until-destroy": "^8.0.4",
        "firebase": "^8.6.5",
        "rxjs": "~6.6.0",
        "tslib": "^2.0.0",
        "zone.js": "~0.11.4"
    },
    "devDependencies": {
        "@angular-devkit/architect": ">= 0.900 < 0.1300",
        "@angular-devkit/build-angular": "~12.0.1",
        "@angular-eslint/builder": "~12.0.0",
        "@angular-eslint/eslint-plugin": "~12.0.0",
        "@angular-eslint/eslint-plugin-template": "~12.0.0",
        "@angular-eslint/template-parser": "~12.0.0",
        "@angular/cli": "~12.0.1",
        "@angular/compiler": "~12.0.1",
        "@angular/compiler-cli": "~12.0.1",
        "@angular/language-service": "~12.0.1",
        "@ionic/angular-toolkit": "^4.0.0",
        "@types/jasmine": "~3.6.0",
        "@types/jasminewd2": "~2.0.3",
        "@types/node": "^12.11.1",
        "@typescript-eslint/eslint-plugin": "4.16.1",
        "@typescript-eslint/parser": "4.16.1",
        "eslint": "^7.6.0",
        "eslint-plugin-import": "2.22.1",
        "eslint-plugin-jsdoc": "30.7.6",
        "eslint-plugin-prefer-arrow": "1.2.2",
        "firebase-tools": "^8.0.0 || ^9.0.0",
        "fuzzy": "^0.1.3",
        "inquirer": "^6.2.2",
        "inquirer-autocomplete-prompt": "^1.0.1",
        "jasmine-core": "~3.7.1",
        "jasmine-spec-reporter": "~5.0.0",
        "jsonc-parser": "^3.0.0",
        "karma": "~6.3.2",
        "karma-chrome-launcher": "~3.1.0",
        "karma-coverage": "~2.0.3",
        "karma-coverage-istanbul-reporter": "~3.0.2",
        "karma-jasmine": "~4.0.0",
        "karma-jasmine-html-reporter": "^1.5.0",
        "open": "^7.0.3",
        "protractor": "~7.0.0",
        "ts-node": "~8.3.0",
        "typescript": "~4.2.4"
    },
    "description": "An Ionic project"
}

package.json from the production app (which works, also with the simple code):

{
    "name": "xx",
    "version": "0.0.1",
    "author": "Ionic Framework",
    "homepage": "https://ionicframework.com/",
    "scripts": {
        "ng": "ng",
        "dev": "ionic serve -w chrome --ssl",
        "deploy": "ionic build --prod &&  firebase deploy --only hosting",
       "start": "ng serve",
        "build": "ng build",
        "test": "ng test",
        "lint": "ng lint",
        "e2e": "ng e2e"
    },
    "private": true,
    "dependencies": {
        "@angular/animations": "^11.2.6",
        "@angular/common": "~11.2.6",
        "@angular/core": "~11.2.6",
        "@angular/fire": "^6.1.4",
        "@angular/forms": "~11.2.6",
        "@angular/google-maps": "^11.2.4",
        "@angular/platform-browser": "~11.2.6",
        "@angular/platform-browser-dynamic": "~11.2.6",
        "@angular/router": "~11.2.6",
        "@angular/service-worker": "~11.2.0",
        "@capacitor/core": "2.4.7",
        "@ionic/angular": "^5.5.2",
        "@ionic/storage": "^3.0.2",
        "@ionic/storage-angular": "^3.0.2",
        "@ngneat/until-destroy": "^8.0.4",
        "firebase": "^7.0 || ^8.0",
        "idb": "^3.0.2",
        "rxjs": "~6.6.0",
        "tslib": "^2.0.0",
        "zone.js": "~0.10.2"
    },
    "devDependencies": {
        "@angular-devkit/architect": ">= 0.900 < 0.1200",
        "@angular-devkit/build-angular": "~0.1102.4",
        "@angular/cli": "~11.2.4",
        "@angular/compiler": "~11.2.6",
        "@angular/compiler-cli": "~11.2.6",
        "@angular/language-service": "~11.2.6",
        "@capacitor/cli": "2.4.7",
        "@ionic/angular-toolkit": "^3.1.1",
        "@types/jasmine": "~3.6.0",
        "@types/jasminewd2": "~2.0.3",
        "@types/node": "^12.11.1",
        "codelyzer": "^6.0.0",
        "firebase-tools": "^8.0.0",
        "fuzzy": "^0.1.3",
        "inquirer": "^6.2.2",
        "inquirer-autocomplete-prompt": "^1.0.1",
        "jasmine-core": "~3.6.0",
        "jasmine-spec-reporter": "~5.0.0",
        "karma": "~5.2.0",
        "karma-chrome-launcher": "~3.1.0",
        "karma-coverage": "~2.0.3",
        "karma-coverage-istanbul-reporter": "~3.0.2",
        "karma-jasmine": "~4.0.0",
        "karma-jasmine-html-reporter": "^1.5.0",
        "open": "^7.0.3",
        "protractor": "~7.0.0",
        "ts-node": "~8.3.0",
        "tslint": "~6.1.0",
        "typescript": "~4.0.2"
    },
    "description": "A project"
}
@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@Tommertom Tommertom changed the title request.auth == null even if user is authenticated (firestore rules) request.auth == null even if user is authenticated (firestore) Jun 8, 2021
@shipley-dcc
Copy link

I have found the same issue.

I have found the issue when using Chrome and Android browsers, however, the issue isn't present when using Firefox.

The issue is present from Firebase version 8.6.2 onwards. Requests are missing the Authorization query paramenter.

@Tommertom
Copy link
Author

Thx. setting firebase to 8.3.0 fixed it as a workaround.

@looptheloop88
Copy link

looptheloop88 commented Jun 9, 2021

Hi @Tommertom, thanks for the report. I will mark this as a duplicate of #4990, since both issues are having similar versions of AngularFire and errors related to Firestore security rules.

@firebase firebase locked and limited conversation to collaborators Jul 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants