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:
Should work the right way. I already looked at the firebase documentation and didn't find more informations.
swift firebase firebase-realtime-database
|
show 2 more comments
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:
Should work the right way. I already looked at the firebase documentation and didn't find more informations.
swift firebase firebase-realtime-database
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
|
show 2 more comments
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:
Should work the right way. I already looked at the firebase documentation and didn't find more informations.
swift firebase firebase-realtime-database
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:
Should work the right way. I already looked at the firebase documentation and didn't find more informations.
swift firebase firebase-realtime-database
swift firebase firebase-realtime-database
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
|
show 2 more comments
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
|
show 2 more comments
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 downloadURL
function 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()
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
add a comment |
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 downloadURL
function 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()
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
add a comment |
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 downloadURL
function 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()
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
add a comment |
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 downloadURL
function 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()
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 downloadURL
function 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()
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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