Pregunta

So,

I've started today with Firebase because it seemed so awsome but i can't even get my app to login a user.

I have used the info found on the website of firebase: https://www.firebase.com/docs/security/simple-login-ios-email-password.html

I use 2 text fields, a register button and a login button (They both use the same textfields).

I've been able to make new accounts but the login gives me back this error:

ERROR:Error Domain=com.firebase Code=9999 "invalid_token" UserInfo=0xb08cfb0 {NSLocalizedDescription=invalid_token}

I make new accounts on my app with the following code:

- (IBAction)register:(id)sender {
    Firebase* ref = [[Firebase alloc] initWithUrl:@"https://videoleersysteem.firebaseIO-demo.com"];
    FirebaseSimpleLogin* authClient = [[FirebaseSimpleLogin alloc] initWithRef:ref];
    NSLog(@"Username:%@", self.usernamefield.text);
    NSLog(@"Password:%@", self.passwordfield.text);

    [authClient createUserWithEmail:self.usernamefield.text password: self.passwordfield.text
                 andCompletionBlock:^(NSError* error, FAUser* user) {

                     if (error != nil) {
                         // There was an error creating the account
                          NSLog(@"ERROR:%@", error);
                     } else {
                         // We created a new user account
                          NSLog(@"SUCCES:%@", self.usernamefield.text);
                     }
                 }];
}

This works.

Then i try to login with the info i just used to register:

- (IBAction)login:(id)sender {
    Firebase* def = [[Firebase alloc] initWithUrl:@"https://videoleersysteem.firebaseIO-demo.com"];
    FirebaseSimpleLogin* authClient = [[FirebaseSimpleLogin alloc] initWithRef:def];
    NSLog(@"Username:%@", self.usernamefield.text);
    NSLog(@"Password:%@", self.passwordfield.text);

    [authClient loginWithEmail:self.usernamefield.text andPassword:self.passwordfield.text
           withCompletionBlock:^(NSError* error, FAUser* user) {

               if (error != nil) {
                   // There was an error logging in to this account
                    NSLog(@"ERROR:%@", error);
                    NSLog(@"USER:%@", user);
               } else {
                   // We are now logged in
                    NSLog(@"SUCCES:%@", self.usernamefield.text);
               }
           }];
}

The console logs this:

2014-04-03 12:53:18.583 VideoLeerSysteem[7456:70b] Username:email@test.nl
2014-04-03 12:53:18.583 VideoLeerSysteem[7456:70b] Password:qwerty1
2014-04-03 12:53:19.609 VideoLeerSysteem[7456:70b] ERROR:Error Domain=com.firebase Code=9999 "invalid_token" UserInfo=0xb08cfb0 {NSLocalizedDescription=invalid_token}
2014-04-03 12:53:19.609 VideoLeerSysteem[7456:70b] USER:(null)

Any experts here who can help a noobie out a tell me what i'm doing wrong?

¿Fue útil?

Solución

It looks like you're using the Firebase url https://videoleersysteem.firebaseIO-demo.com, but that should probably be https://videoleersysteem.firebaseIO.com, as you can't authenticate against the 'demo' server. Let me know if that helps!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top