Swift, Firebase: No datas in realtime database after creating user









up vote
1
down vote

favorite












Using Xcode 10.1, Swift 4.2 and Firebase ##



I can't see datas in my realtime database after uploading the datas to firebase with the following code:



static func createUser(username: String, email: String, password: String, imageData: Data, onSuccess: @escaping () -> Void, onError: @escaping (_ error: String?) -> Void) 

Auth.auth().createUser(withEmail: email, password: password) (data, error) in
if let err = error
onError(err.localizedDescription)
return

// User erfolgreich erstellt
guard let uid = data?.user.uid else return
self.uploadUserData(uid: uid, username: username, email: email, imageData: imageData, onSuccess: onSuccess)



static func uploadUserData(uid: String, username: String, email: String, imageData: Data, onSuccess: @escaping () -> Void)


let storageRef = Storage.storage().reference().child("profile_image").child(uid)

storageRef.putData(imageData, metadata: nil) (metadata, error) in
if error != nil
return



storageRef.downloadURL(completion: (url, error) in
if error != nil
print(error!.localizedDescription)
return


let profilImageURL = url?.absoluteString


let ref = Database.database().reference().child("users").child(uid)
ref.setValue(["username" : username, "email" : email, "profileImageURL": profilImageURL ?? "Kein Bild vorhanden"])

)
onSuccess()



The settings in firebase:



The settings in firebase



Should work the right way. I already looked at the firebase documentation and didn't find more informations.










share|improve this question























  • Are you sure the user has write permission to /users/$uid?
    – Frank van Puffelen
    Nov 9 at 17:56










  • sorry my mistake. edited the picture. read and write is on true.
    – jo_h_es
    Nov 9 at 18:01










  • Thanks for sharing that. Please always post textual content as text. Pictures of text are not nearly as reusable, and searchable.
    – Frank van Puffelen
    Nov 9 at 18:21










  • So you're saying your database remains empty after running this code?
    – Frank van Puffelen
    Nov 9 at 18:22










  • yes after this code my realtime database is empty
    – jo_h_es
    Nov 9 at 19:53














up vote
1
down vote

favorite












Using Xcode 10.1, Swift 4.2 and Firebase ##



I can't see datas in my realtime database after uploading the datas to firebase with the following code:



static func createUser(username: String, email: String, password: String, imageData: Data, onSuccess: @escaping () -> Void, onError: @escaping (_ error: String?) -> Void) 

Auth.auth().createUser(withEmail: email, password: password) (data, error) in
if let err = error
onError(err.localizedDescription)
return

// User erfolgreich erstellt
guard let uid = data?.user.uid else return
self.uploadUserData(uid: uid, username: username, email: email, imageData: imageData, onSuccess: onSuccess)



static func uploadUserData(uid: String, username: String, email: String, imageData: Data, onSuccess: @escaping () -> Void)


let storageRef = Storage.storage().reference().child("profile_image").child(uid)

storageRef.putData(imageData, metadata: nil) (metadata, error) in
if error != nil
return



storageRef.downloadURL(completion: (url, error) in
if error != nil
print(error!.localizedDescription)
return


let profilImageURL = url?.absoluteString


let ref = Database.database().reference().child("users").child(uid)
ref.setValue(["username" : username, "email" : email, "profileImageURL": profilImageURL ?? "Kein Bild vorhanden"])

)
onSuccess()



The settings in firebase:



The settings in firebase



Should work the right way. I already looked at the firebase documentation and didn't find more informations.










share|improve this question























  • Are you sure the user has write permission to /users/$uid?
    – Frank van Puffelen
    Nov 9 at 17:56










  • sorry my mistake. edited the picture. read and write is on true.
    – jo_h_es
    Nov 9 at 18:01










  • Thanks for sharing that. Please always post textual content as text. Pictures of text are not nearly as reusable, and searchable.
    – Frank van Puffelen
    Nov 9 at 18:21










  • So you're saying your database remains empty after running this code?
    – Frank van Puffelen
    Nov 9 at 18:22










  • yes after this code my realtime database is empty
    – jo_h_es
    Nov 9 at 19:53












up vote
1
down vote

favorite









up vote
1
down vote

favorite











Using Xcode 10.1, Swift 4.2 and Firebase ##



I can't see datas in my realtime database after uploading the datas to firebase with the following code:



static func createUser(username: String, email: String, password: String, imageData: Data, onSuccess: @escaping () -> Void, onError: @escaping (_ error: String?) -> Void) 

Auth.auth().createUser(withEmail: email, password: password) (data, error) in
if let err = error
onError(err.localizedDescription)
return

// User erfolgreich erstellt
guard let uid = data?.user.uid else return
self.uploadUserData(uid: uid, username: username, email: email, imageData: imageData, onSuccess: onSuccess)



static func uploadUserData(uid: String, username: String, email: String, imageData: Data, onSuccess: @escaping () -> Void)


let storageRef = Storage.storage().reference().child("profile_image").child(uid)

storageRef.putData(imageData, metadata: nil) (metadata, error) in
if error != nil
return



storageRef.downloadURL(completion: (url, error) in
if error != nil
print(error!.localizedDescription)
return


let profilImageURL = url?.absoluteString


let ref = Database.database().reference().child("users").child(uid)
ref.setValue(["username" : username, "email" : email, "profileImageURL": profilImageURL ?? "Kein Bild vorhanden"])

)
onSuccess()



The settings in firebase:



The settings in firebase



Should work the right way. I already looked at the firebase documentation and didn't find more informations.










share|improve this question















Using Xcode 10.1, Swift 4.2 and Firebase ##



I can't see datas in my realtime database after uploading the datas to firebase with the following code:



static func createUser(username: String, email: String, password: String, imageData: Data, onSuccess: @escaping () -> Void, onError: @escaping (_ error: String?) -> Void) 

Auth.auth().createUser(withEmail: email, password: password) (data, error) in
if let err = error
onError(err.localizedDescription)
return

// User erfolgreich erstellt
guard let uid = data?.user.uid else return
self.uploadUserData(uid: uid, username: username, email: email, imageData: imageData, onSuccess: onSuccess)



static func uploadUserData(uid: String, username: String, email: String, imageData: Data, onSuccess: @escaping () -> Void)


let storageRef = Storage.storage().reference().child("profile_image").child(uid)

storageRef.putData(imageData, metadata: nil) (metadata, error) in
if error != nil
return



storageRef.downloadURL(completion: (url, error) in
if error != nil
print(error!.localizedDescription)
return


let profilImageURL = url?.absoluteString


let ref = Database.database().reference().child("users").child(uid)
ref.setValue(["username" : username, "email" : email, "profileImageURL": profilImageURL ?? "Kein Bild vorhanden"])

)
onSuccess()



The settings in firebase:



The settings in firebase



Should work the right way. I already looked at the firebase documentation and didn't find more informations.







swift firebase firebase-realtime-database






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 18:00

























asked Nov 9 at 17:47









jo_h_es

157




157











  • Are you sure the user has write permission to /users/$uid?
    – Frank van Puffelen
    Nov 9 at 17:56










  • sorry my mistake. edited the picture. read and write is on true.
    – jo_h_es
    Nov 9 at 18:01










  • Thanks for sharing that. Please always post textual content as text. Pictures of text are not nearly as reusable, and searchable.
    – Frank van Puffelen
    Nov 9 at 18:21










  • So you're saying your database remains empty after running this code?
    – Frank van Puffelen
    Nov 9 at 18:22










  • yes after this code my realtime database is empty
    – jo_h_es
    Nov 9 at 19:53
















  • Are you sure the user has write permission to /users/$uid?
    – Frank van Puffelen
    Nov 9 at 17:56










  • sorry my mistake. edited the picture. read and write is on true.
    – jo_h_es
    Nov 9 at 18:01










  • Thanks for sharing that. Please always post textual content as text. Pictures of text are not nearly as reusable, and searchable.
    – Frank van Puffelen
    Nov 9 at 18:21










  • So you're saying your database remains empty after running this code?
    – Frank van Puffelen
    Nov 9 at 18:22










  • yes after this code my realtime database is empty
    – jo_h_es
    Nov 9 at 19:53















Are you sure the user has write permission to /users/$uid?
– Frank van Puffelen
Nov 9 at 17:56




Are you sure the user has write permission to /users/$uid?
– Frank van Puffelen
Nov 9 at 17:56












sorry my mistake. edited the picture. read and write is on true.
– jo_h_es
Nov 9 at 18:01




sorry my mistake. edited the picture. read and write is on true.
– jo_h_es
Nov 9 at 18:01












Thanks for sharing that. Please always post textual content as text. Pictures of text are not nearly as reusable, and searchable.
– Frank van Puffelen
Nov 9 at 18:21




Thanks for sharing that. Please always post textual content as text. Pictures of text are not nearly as reusable, and searchable.
– Frank van Puffelen
Nov 9 at 18:21












So you're saying your database remains empty after running this code?
– Frank van Puffelen
Nov 9 at 18:22




So you're saying your database remains empty after running this code?
– Frank van Puffelen
Nov 9 at 18:22












yes after this code my realtime database is empty
– jo_h_es
Nov 9 at 19:53




yes after this code my realtime database is empty
– jo_h_es
Nov 9 at 19:53












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Does the image get uploaded to Cloud Storage? If it does but the download URL isn't written to the database, my guess is it's because the data isn't uploaded before you generate the download URL. Since the upload function is asynchronous, the downloadURLfunction should be called from the closure.



static func uploadUserData(uid: String, username: String, email: String, imageData: Data, onSuccess: @escaping () -> Void) {

let storageRef = Storage.storage().reference().child("profile_image").child(uid)

storageRef.putData(imageData, metadata: nil) (metadata, error) in
if error != nil
return

storageRef.downloadURL(completion: (url, error) in
if error != nil
print(error!.localizedDescription)
return

onSuccess()







share|improve this answer




















  • Yes the Picture get uploaded to the storage. But not the user data.
    – jo_h_es
    Nov 9 at 18:51










  • Did you try my suggestion then?
    – Jen Person
    Nov 9 at 21:19










  • FIXED: I closed the bracket too early. Thank you very much for your help! :)
    – jo_h_es
    Nov 9 at 23:10










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',
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%2f53230887%2fswift-firebase-no-datas-in-realtime-database-after-creating-user%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








up vote
1
down vote



accepted










Does the image get uploaded to Cloud Storage? If it does but the download URL isn't written to the database, my guess is it's because the data isn't uploaded before you generate the download URL. Since the upload function is asynchronous, the downloadURLfunction should be called from the closure.



static func uploadUserData(uid: String, username: String, email: String, imageData: Data, onSuccess: @escaping () -> Void) {

let storageRef = Storage.storage().reference().child("profile_image").child(uid)

storageRef.putData(imageData, metadata: nil) (metadata, error) in
if error != nil
return

storageRef.downloadURL(completion: (url, error) in
if error != nil
print(error!.localizedDescription)
return

onSuccess()







share|improve this answer




















  • Yes the Picture get uploaded to the storage. But not the user data.
    – jo_h_es
    Nov 9 at 18:51










  • Did you try my suggestion then?
    – Jen Person
    Nov 9 at 21:19










  • FIXED: I closed the bracket too early. Thank you very much for your help! :)
    – jo_h_es
    Nov 9 at 23:10














up vote
1
down vote



accepted










Does the image get uploaded to Cloud Storage? If it does but the download URL isn't written to the database, my guess is it's because the data isn't uploaded before you generate the download URL. Since the upload function is asynchronous, the downloadURLfunction should be called from the closure.



static func uploadUserData(uid: String, username: String, email: String, imageData: Data, onSuccess: @escaping () -> Void) {

let storageRef = Storage.storage().reference().child("profile_image").child(uid)

storageRef.putData(imageData, metadata: nil) (metadata, error) in
if error != nil
return

storageRef.downloadURL(completion: (url, error) in
if error != nil
print(error!.localizedDescription)
return

onSuccess()







share|improve this answer




















  • Yes the Picture get uploaded to the storage. But not the user data.
    – jo_h_es
    Nov 9 at 18:51










  • Did you try my suggestion then?
    – Jen Person
    Nov 9 at 21:19










  • FIXED: I closed the bracket too early. Thank you very much for your help! :)
    – jo_h_es
    Nov 9 at 23:10












up vote
1
down vote



accepted







up vote
1
down vote



accepted






Does the image get uploaded to Cloud Storage? If it does but the download URL isn't written to the database, my guess is it's because the data isn't uploaded before you generate the download URL. Since the upload function is asynchronous, the downloadURLfunction should be called from the closure.



static func uploadUserData(uid: String, username: String, email: String, imageData: Data, onSuccess: @escaping () -> Void) {

let storageRef = Storage.storage().reference().child("profile_image").child(uid)

storageRef.putData(imageData, metadata: nil) (metadata, error) in
if error != nil
return

storageRef.downloadURL(completion: (url, error) in
if error != nil
print(error!.localizedDescription)
return

onSuccess()







share|improve this answer












Does the image get uploaded to Cloud Storage? If it does but the download URL isn't written to the database, my guess is it's because the data isn't uploaded before you generate the download URL. Since the upload function is asynchronous, the downloadURLfunction should be called from the closure.



static func uploadUserData(uid: String, username: String, email: String, imageData: Data, onSuccess: @escaping () -> Void) {

let storageRef = Storage.storage().reference().child("profile_image").child(uid)

storageRef.putData(imageData, metadata: nil) (metadata, error) in
if error != nil
return

storageRef.downloadURL(completion: (url, error) in
if error != nil
print(error!.localizedDescription)
return

onSuccess()








share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 9 at 18:41









Jen Person

4,633521




4,633521











  • Yes the Picture get uploaded to the storage. But not the user data.
    – jo_h_es
    Nov 9 at 18:51










  • Did you try my suggestion then?
    – Jen Person
    Nov 9 at 21:19










  • FIXED: I closed the bracket too early. Thank you very much for your help! :)
    – jo_h_es
    Nov 9 at 23:10
















  • Yes the Picture get uploaded to the storage. But not the user data.
    – jo_h_es
    Nov 9 at 18:51










  • Did you try my suggestion then?
    – Jen Person
    Nov 9 at 21:19










  • FIXED: I closed the bracket too early. Thank you very much for your help! :)
    – jo_h_es
    Nov 9 at 23:10















Yes the Picture get uploaded to the storage. But not the user data.
– jo_h_es
Nov 9 at 18:51




Yes the Picture get uploaded to the storage. But not the user data.
– jo_h_es
Nov 9 at 18:51












Did you try my suggestion then?
– Jen Person
Nov 9 at 21:19




Did you try my suggestion then?
– Jen Person
Nov 9 at 21:19












FIXED: I closed the bracket too early. Thank you very much for your help! :)
– jo_h_es
Nov 9 at 23:10




FIXED: I closed the bracket too early. Thank you very much for your help! :)
– jo_h_es
Nov 9 at 23:10

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230887%2fswift-firebase-no-datas-in-realtime-database-after-creating-user%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

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo