Any help would be greatly appreciated. I have a web app I have been using for a time clock system for my company. The other day the Gemini and I were adding some features, and it prompted me to connect to Firebase Authentication. This is my first web app so I just clicked that. The way my web app was working, my user logins are stored inside the firestore database. All clock in/out times, timesheet signatures, etc gets stored on there and it was working great. But ever since it added the authentication, I can’t login and says I’m missing permissions. I’ve been trying to fix it for weeks now and cannot figure it out. Any suggestions?? Thanks
Could you post the contents / screenshots of the errors you’re getting? Is there a generated firebase.rules file in your project?
Double check your firebase.rules and verify in the Authentication tab if you have Email and Google Sign-in enabled (or whatever provider you use).
An probably skip the fix now error prompt and give Gemini more context to work on.
Yes, I have made some progress. It does tell me successfully logged in now when typing the email and password I setup, but then right before it should redirect me to the next page, it refreshes back to the login screen and says this.
FirebaseError: Missing or insufficient permissions.
FirestorePermissionError: Firestore permission denied for operation ‘get’ on path ‘users/VvFqNpJqNANKjUfpvk5a1VmP4ox2’.
src/lib/data.ts (88:33) @ findUserById
86 | } catch(e: any) {
87 | if (e.code === 'permission-denied') {
> 88 | const customError = new FirestorePermissionError({
| ^
89 | path: userDocRef.path,
90 | operation: 'get',
91 | });
Call Stack2
findUserById
src/lib/data.ts (88:33)
async AppLayout.useEffect.checkUser
src/app/app/layout.tsx (57:29)
Here are my firestore rules.
rules_version = ‘2’;
service cloud.firestore {
match /databases/{database}/documents {
// Helper function to check if the requesting user is the owner of a document.
function isOwner(userId) {
return request.auth != null && request.auth.uid == userId;
}
// Helper function to check if the user has the 'manager' role.
// This requires reading the user's own profile.
function isManager() {
return request.auth != null && get(/databases/$(database)/documents/users/$(request.auth.uid)).data.role == 'manager';
}
// Rule for the 'users' collection
match /users/{userId} {
// Allow a user to read their own profile.
// Allow a manager to read any user's profile.
allow get: if isOwner(userId) || isManager();
// Allow managers to list all users.
allow list: if isManager();
// Allow a user to update their own profile.
// Allow a manager to update any user's profile.
allow update: if isOwner(userId) || isManager();
// Only managers can create or delete user profiles.
allow create, delete: if isManager();
}
match /timeEntries/{docId} {
allow read, write: if isManager() || isOwner(resource.data.userId);
}
match /tasks/{docId} {
allow read, write: if isManager() || isOwner(resource.data.assignedTo);
}
match /signatures/{docId} {
allow read, write: if isManager() || isOwner(resource.data.userId);
}
match /holidays/{docId} {
allow read: if request.auth != null;
allow write: if isManager();
}
match /companySettings/{docId} {
allow read: if request.auth != null;
allow write: if isManager();
}
}
}
Yes, thank you I have verified that is enabled.
currently no, this particular user i chose to setup first just needs the employee role. which should just log him in to see his timesheet for the week and submit. the manager role shees dashboards, etc when logged in.
Looking at the rules playground those rules look good to allow that read, so it may be the authentication connection that isn’t working. Does the error message you’re seeing have details about the auth context?
When I try to login with a user, I keep getting these errors. I’m honestly a little above my head in understanding how to fix this. I have added users in the authentication tab inside the console for the project. Then I added the user as a document in the firestore database. That from what I understand is all I need to login no? Let me know if there is any other code I should paste in, I am relying some on the Gemini to help so it changes things sometimes but still can’t fix this issue seems like.
FirebaseError: Missing or insufficient permissions.
FirestorePermissionError: Firestore permission denied for operation ‘get’ on path ‘users/VvFqNpJqNANKjUfpvk5a1VmP4ox2’.
at findUserById (https://6000-firebase-studio-1758115390126.cluster-57i2ylwve5fskth4xb2kui2ow2.cloudworkstations.dev/_next/static/chunks/src_93acd971._.js:1405:33)
at async AppLayout.useEffect.checkUser (https://6000-firebase-studio-1758115390126.cluster-57i2ylwve5fskth4xb2kui2ow2.cloudworkstations.dev/_next/static/chunks/src_93acd971._.js:2441:45)
As Sam stated the rules are good, probably the error comes from the inside of your code. Most likely inside of src/lib/data.ts
