Firebase Database Authentication Swift





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I implemented the log-in and registration views for the Authentication via Firebase. Then how can I authenticate to my database? I changed the rules and I put:



{
"rules": {
"users": {
"$uid": {
".write": "$uid === auth.uid"
}
}
}
}


I also wrote the code for obtain the User UID, but how can I say to my database that I'm authenticated?



PS: I need the example in Swift.










share|improve this question

























  • Should help: firebase.google.com/docs/auth/ios/start

    – Sayalee Pote
    Nov 16 '18 at 13:11











  • I already checked it. The fact is, when I'm logging in, I'm receiving the UID and with this UID how can I say to my database that I can have the right permissions?

    – Pietro Messineo
    Nov 16 '18 at 13:12













  • I am having a hard time understandnig your question. The rules you shared validate that a user can only write their own node. What problem are you having with the corresponding code?

    – Frank van Puffelen
    Nov 16 '18 at 14:11











  • Basically I want to read from my database, after that I set that rules above. But when I'm trying to do it I'm receiving the message: failed: permission_denied on console. For read I'm using: let ref = Database.database().reference() ref.child("utenti").observe(.value) { (snap) in .....

    – Pietro Messineo
    Nov 16 '18 at 16:17











  • The question is pretty unclear, and the above comment adds to the confusion. Are you saying you want to change the rules on the fly? As in I want to read from my database and then after that I set that rules above? Why would you want to do that? Can you provide a use case and or perhaps some code that demonstrates what you're trying to do? Please take a moment and review How do I ask a good question? and How to create a Minimal, Complete, and Verifiable example

    – Jay
    Nov 16 '18 at 18:39


















0















I implemented the log-in and registration views for the Authentication via Firebase. Then how can I authenticate to my database? I changed the rules and I put:



{
"rules": {
"users": {
"$uid": {
".write": "$uid === auth.uid"
}
}
}
}


I also wrote the code for obtain the User UID, but how can I say to my database that I'm authenticated?



PS: I need the example in Swift.










share|improve this question

























  • Should help: firebase.google.com/docs/auth/ios/start

    – Sayalee Pote
    Nov 16 '18 at 13:11











  • I already checked it. The fact is, when I'm logging in, I'm receiving the UID and with this UID how can I say to my database that I can have the right permissions?

    – Pietro Messineo
    Nov 16 '18 at 13:12













  • I am having a hard time understandnig your question. The rules you shared validate that a user can only write their own node. What problem are you having with the corresponding code?

    – Frank van Puffelen
    Nov 16 '18 at 14:11











  • Basically I want to read from my database, after that I set that rules above. But when I'm trying to do it I'm receiving the message: failed: permission_denied on console. For read I'm using: let ref = Database.database().reference() ref.child("utenti").observe(.value) { (snap) in .....

    – Pietro Messineo
    Nov 16 '18 at 16:17











  • The question is pretty unclear, and the above comment adds to the confusion. Are you saying you want to change the rules on the fly? As in I want to read from my database and then after that I set that rules above? Why would you want to do that? Can you provide a use case and or perhaps some code that demonstrates what you're trying to do? Please take a moment and review How do I ask a good question? and How to create a Minimal, Complete, and Verifiable example

    – Jay
    Nov 16 '18 at 18:39














0












0








0








I implemented the log-in and registration views for the Authentication via Firebase. Then how can I authenticate to my database? I changed the rules and I put:



{
"rules": {
"users": {
"$uid": {
".write": "$uid === auth.uid"
}
}
}
}


I also wrote the code for obtain the User UID, but how can I say to my database that I'm authenticated?



PS: I need the example in Swift.










share|improve this question
















I implemented the log-in and registration views for the Authentication via Firebase. Then how can I authenticate to my database? I changed the rules and I put:



{
"rules": {
"users": {
"$uid": {
".write": "$uid === auth.uid"
}
}
}
}


I also wrote the code for obtain the User UID, but how can I say to my database that I'm authenticated?



PS: I need the example in Swift.







swift firebase firebase-realtime-database firebase-security-rules






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 14:09









Frank van Puffelen

245k30389418




245k30389418










asked Nov 16 '18 at 12:26









Pietro MessineoPietro Messineo

133212




133212













  • Should help: firebase.google.com/docs/auth/ios/start

    – Sayalee Pote
    Nov 16 '18 at 13:11











  • I already checked it. The fact is, when I'm logging in, I'm receiving the UID and with this UID how can I say to my database that I can have the right permissions?

    – Pietro Messineo
    Nov 16 '18 at 13:12













  • I am having a hard time understandnig your question. The rules you shared validate that a user can only write their own node. What problem are you having with the corresponding code?

    – Frank van Puffelen
    Nov 16 '18 at 14:11











  • Basically I want to read from my database, after that I set that rules above. But when I'm trying to do it I'm receiving the message: failed: permission_denied on console. For read I'm using: let ref = Database.database().reference() ref.child("utenti").observe(.value) { (snap) in .....

    – Pietro Messineo
    Nov 16 '18 at 16:17











  • The question is pretty unclear, and the above comment adds to the confusion. Are you saying you want to change the rules on the fly? As in I want to read from my database and then after that I set that rules above? Why would you want to do that? Can you provide a use case and or perhaps some code that demonstrates what you're trying to do? Please take a moment and review How do I ask a good question? and How to create a Minimal, Complete, and Verifiable example

    – Jay
    Nov 16 '18 at 18:39



















  • Should help: firebase.google.com/docs/auth/ios/start

    – Sayalee Pote
    Nov 16 '18 at 13:11











  • I already checked it. The fact is, when I'm logging in, I'm receiving the UID and with this UID how can I say to my database that I can have the right permissions?

    – Pietro Messineo
    Nov 16 '18 at 13:12













  • I am having a hard time understandnig your question. The rules you shared validate that a user can only write their own node. What problem are you having with the corresponding code?

    – Frank van Puffelen
    Nov 16 '18 at 14:11











  • Basically I want to read from my database, after that I set that rules above. But when I'm trying to do it I'm receiving the message: failed: permission_denied on console. For read I'm using: let ref = Database.database().reference() ref.child("utenti").observe(.value) { (snap) in .....

    – Pietro Messineo
    Nov 16 '18 at 16:17











  • The question is pretty unclear, and the above comment adds to the confusion. Are you saying you want to change the rules on the fly? As in I want to read from my database and then after that I set that rules above? Why would you want to do that? Can you provide a use case and or perhaps some code that demonstrates what you're trying to do? Please take a moment and review How do I ask a good question? and How to create a Minimal, Complete, and Verifiable example

    – Jay
    Nov 16 '18 at 18:39

















Should help: firebase.google.com/docs/auth/ios/start

– Sayalee Pote
Nov 16 '18 at 13:11





Should help: firebase.google.com/docs/auth/ios/start

– Sayalee Pote
Nov 16 '18 at 13:11













I already checked it. The fact is, when I'm logging in, I'm receiving the UID and with this UID how can I say to my database that I can have the right permissions?

– Pietro Messineo
Nov 16 '18 at 13:12







I already checked it. The fact is, when I'm logging in, I'm receiving the UID and with this UID how can I say to my database that I can have the right permissions?

– Pietro Messineo
Nov 16 '18 at 13:12















I am having a hard time understandnig your question. The rules you shared validate that a user can only write their own node. What problem are you having with the corresponding code?

– Frank van Puffelen
Nov 16 '18 at 14:11





I am having a hard time understandnig your question. The rules you shared validate that a user can only write their own node. What problem are you having with the corresponding code?

– Frank van Puffelen
Nov 16 '18 at 14:11













Basically I want to read from my database, after that I set that rules above. But when I'm trying to do it I'm receiving the message: failed: permission_denied on console. For read I'm using: let ref = Database.database().reference() ref.child("utenti").observe(.value) { (snap) in .....

– Pietro Messineo
Nov 16 '18 at 16:17





Basically I want to read from my database, after that I set that rules above. But when I'm trying to do it I'm receiving the message: failed: permission_denied on console. For read I'm using: let ref = Database.database().reference() ref.child("utenti").observe(.value) { (snap) in .....

– Pietro Messineo
Nov 16 '18 at 16:17













The question is pretty unclear, and the above comment adds to the confusion. Are you saying you want to change the rules on the fly? As in I want to read from my database and then after that I set that rules above? Why would you want to do that? Can you provide a use case and or perhaps some code that demonstrates what you're trying to do? Please take a moment and review How do I ask a good question? and How to create a Minimal, Complete, and Verifiable example

– Jay
Nov 16 '18 at 18:39





The question is pretty unclear, and the above comment adds to the confusion. Are you saying you want to change the rules on the fly? As in I want to read from my database and then after that I set that rules above? Why would you want to do that? Can you provide a use case and or perhaps some code that demonstrates what you're trying to do? Please take a moment and review How do I ask a good question? and How to create a Minimal, Complete, and Verifiable example

– Jay
Nov 16 '18 at 18:39












1 Answer
1






active

oldest

votes


















0














try the following format:



cloud firestore



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


realtime database



// Checks auth uid equals database node uid



// In other words, the User can only access their own data



{
"rules": {
"users": {
"$uid": {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid"
}
}
}
}





share|improve this answer


























  • The real time database, set as you said will let all the people to be able to access to the database...

    – Pietro Messineo
    Nov 16 '18 at 20:19











  • There's an update that ensures the user can only access their own data. That is just a random example, if you can give me more details as to what you want your rules to be like, then I would be able to be more accurate.

    – Tajh McDonald
    Nov 16 '18 at 20:26











  • Yes! I done a main view with the log in, and I want that the UID of this user will be able to access to the database. How can I do this? Because with the above rules, everyone can read and write.

    – Pietro Messineo
    Nov 16 '18 at 20:28











  • see the updated code, that ensures a certain user can access their own data and not everything

    – Tajh McDonald
    Nov 16 '18 at 20:29











  • And Swift side?

    – Pietro Messineo
    Nov 16 '18 at 20:31












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337904%2ffirebase-database-authentication-swift%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














try the following format:



cloud firestore



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


realtime database



// Checks auth uid equals database node uid



// In other words, the User can only access their own data



{
"rules": {
"users": {
"$uid": {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid"
}
}
}
}





share|improve this answer


























  • The real time database, set as you said will let all the people to be able to access to the database...

    – Pietro Messineo
    Nov 16 '18 at 20:19











  • There's an update that ensures the user can only access their own data. That is just a random example, if you can give me more details as to what you want your rules to be like, then I would be able to be more accurate.

    – Tajh McDonald
    Nov 16 '18 at 20:26











  • Yes! I done a main view with the log in, and I want that the UID of this user will be able to access to the database. How can I do this? Because with the above rules, everyone can read and write.

    – Pietro Messineo
    Nov 16 '18 at 20:28











  • see the updated code, that ensures a certain user can access their own data and not everything

    – Tajh McDonald
    Nov 16 '18 at 20:29











  • And Swift side?

    – Pietro Messineo
    Nov 16 '18 at 20:31
















0














try the following format:



cloud firestore



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


realtime database



// Checks auth uid equals database node uid



// In other words, the User can only access their own data



{
"rules": {
"users": {
"$uid": {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid"
}
}
}
}





share|improve this answer


























  • The real time database, set as you said will let all the people to be able to access to the database...

    – Pietro Messineo
    Nov 16 '18 at 20:19











  • There's an update that ensures the user can only access their own data. That is just a random example, if you can give me more details as to what you want your rules to be like, then I would be able to be more accurate.

    – Tajh McDonald
    Nov 16 '18 at 20:26











  • Yes! I done a main view with the log in, and I want that the UID of this user will be able to access to the database. How can I do this? Because with the above rules, everyone can read and write.

    – Pietro Messineo
    Nov 16 '18 at 20:28











  • see the updated code, that ensures a certain user can access their own data and not everything

    – Tajh McDonald
    Nov 16 '18 at 20:29











  • And Swift side?

    – Pietro Messineo
    Nov 16 '18 at 20:31














0












0








0







try the following format:



cloud firestore



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


realtime database



// Checks auth uid equals database node uid



// In other words, the User can only access their own data



{
"rules": {
"users": {
"$uid": {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid"
}
}
}
}





share|improve this answer















try the following format:



cloud firestore



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


realtime database



// Checks auth uid equals database node uid



// In other words, the User can only access their own data



{
"rules": {
"users": {
"$uid": {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid"
}
}
}
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 16 '18 at 20:30

























answered Nov 16 '18 at 19:58









Tajh McDonaldTajh McDonald

115




115













  • The real time database, set as you said will let all the people to be able to access to the database...

    – Pietro Messineo
    Nov 16 '18 at 20:19











  • There's an update that ensures the user can only access their own data. That is just a random example, if you can give me more details as to what you want your rules to be like, then I would be able to be more accurate.

    – Tajh McDonald
    Nov 16 '18 at 20:26











  • Yes! I done a main view with the log in, and I want that the UID of this user will be able to access to the database. How can I do this? Because with the above rules, everyone can read and write.

    – Pietro Messineo
    Nov 16 '18 at 20:28











  • see the updated code, that ensures a certain user can access their own data and not everything

    – Tajh McDonald
    Nov 16 '18 at 20:29











  • And Swift side?

    – Pietro Messineo
    Nov 16 '18 at 20:31



















  • The real time database, set as you said will let all the people to be able to access to the database...

    – Pietro Messineo
    Nov 16 '18 at 20:19











  • There's an update that ensures the user can only access their own data. That is just a random example, if you can give me more details as to what you want your rules to be like, then I would be able to be more accurate.

    – Tajh McDonald
    Nov 16 '18 at 20:26











  • Yes! I done a main view with the log in, and I want that the UID of this user will be able to access to the database. How can I do this? Because with the above rules, everyone can read and write.

    – Pietro Messineo
    Nov 16 '18 at 20:28











  • see the updated code, that ensures a certain user can access their own data and not everything

    – Tajh McDonald
    Nov 16 '18 at 20:29











  • And Swift side?

    – Pietro Messineo
    Nov 16 '18 at 20:31

















The real time database, set as you said will let all the people to be able to access to the database...

– Pietro Messineo
Nov 16 '18 at 20:19





The real time database, set as you said will let all the people to be able to access to the database...

– Pietro Messineo
Nov 16 '18 at 20:19













There's an update that ensures the user can only access their own data. That is just a random example, if you can give me more details as to what you want your rules to be like, then I would be able to be more accurate.

– Tajh McDonald
Nov 16 '18 at 20:26





There's an update that ensures the user can only access their own data. That is just a random example, if you can give me more details as to what you want your rules to be like, then I would be able to be more accurate.

– Tajh McDonald
Nov 16 '18 at 20:26













Yes! I done a main view with the log in, and I want that the UID of this user will be able to access to the database. How can I do this? Because with the above rules, everyone can read and write.

– Pietro Messineo
Nov 16 '18 at 20:28





Yes! I done a main view with the log in, and I want that the UID of this user will be able to access to the database. How can I do this? Because with the above rules, everyone can read and write.

– Pietro Messineo
Nov 16 '18 at 20:28













see the updated code, that ensures a certain user can access their own data and not everything

– Tajh McDonald
Nov 16 '18 at 20:29





see the updated code, that ensures a certain user can access their own data and not everything

– Tajh McDonald
Nov 16 '18 at 20:29













And Swift side?

– Pietro Messineo
Nov 16 '18 at 20:31





And Swift side?

– Pietro Messineo
Nov 16 '18 at 20:31




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337904%2ffirebase-database-authentication-swift%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues