Closed haroonabbasi closed 8 years ago
Null URL. that's interesting.
this is the URL that is composed to for the "exchangeForToken" logic:
let exchangeForTokenUrl = this.config.baseUrl ? joinUrl(this.config.baseUrl, this.defaults.url) : this.defaults.url;
As you can see, when you define your url it cannot be null... and you say it's not so how do you get a null URL?
Can you share the login component and the module code?
Hi, thanks for replying so quickly!
the app.module.ts file code
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { HttpModule } from '@angular/http';
// used to create fake backend
import { fakeBackendProvider } from './helpers/fake-backend';
import { MockBackend, MockConnection } from '@angular/http/testing';
import { BaseRequestOptions } from '@angular/http';
import { AuthGuard } from './guards/auth.guard';
import { AuthenticationService } from './services/authentication.service';
import { UserService } from './services/user.service';
import { LoginComponent } from './components/login/login.component';
import {Ng2UiAuthModule} from 'ng2-ui-auth';
import { MyAuthConfig } from './my-auth-config';
// Imports for loading & configuring the in-memory web api
import { InMemoryWebApiModule } from 'angular-in-memory-web-api/in-memory-web-api.module';
import { InMemoryDataService } from './in-memory-data.service';
import { AppComponent } from './components/app.component';
import { DashboardComponent } from './components/dashboard/dashboard.component';
import { HeroesComponent } from './components/heroes/heroes.component';
import { HeroDetailComponent } from './components/heroes/hero-detail.component';
import { HeroService } from './services/hero.service';
import { AppRoutingModule } from './app-routing.module';
@NgModule({
imports: [
BrowserModule,
FormsModule,
HttpModule,
InMemoryWebApiModule.forRoot(InMemoryDataService),
AppRoutingModule,
Ng2UiAuthModule.getWithConfig(MyAuthConfig)
],
declarations: [
AppComponent,
LoginComponent,
DashboardComponent,
HeroesComponent,
HeroDetailComponent
],
providers: [
AuthGuard,
AuthenticationService,
UserService,
// providers used to create fake backend
//fakeBackendProvider,
//MockBackend,
//BaseRequestOptions,
HeroService
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
The login.component.ts File code
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import {AuthService} from 'ng2-ui-auth';
import { AuthenticationService } from '../../services/authentication.service';
@Component({
moduleId: module.id,
templateUrl: 'login.component.html'
})
export class LoginComponent implements OnInit {
model: any = {};
loading = false;
error = '';
constructor(
private router: Router,
private authenticationService: AuthenticationService,
private auth: AuthService,
) { }
ngOnInit() {
// reset login status
this.authenticationService.logout();
}
login() {
this.loading = true;
this.authenticationService.login(this.model.username, this.model.password)
.subscribe(result => {
if (result === true) {
// login successful
this.router.navigate(['/']);
} else {
// login failed
this.error = 'Username or password is incorrect';
this.loading = false;
}
});
}
loginWithGoogle() {
this.auth.authenticate('google')
.subscribe({
error: (err: any) => {
console.log('Error :' + err);
//this.error = 'Username or password is incorrect';
//this.loading = false;
},
complete: () => {
this.router.navigateByUrl('dashboard');
}
});
}
loginWithFacebook() {
this.auth.authenticate('facebook')
.subscribe({
error: (err: any) => {
console.log('Error :' + err);
//this.error = 'Username or password is incorrect';
//this.loading = false;
},
complete: () => {
this.router.navigateByUrl('dashboard');
}
});
}
}
Everything looks in order... I've tried to reproduce it and seems like it works for me...
if you used the satellizer example you should have the morgan logs, can you show them?
if you don't even get there can you give me the exact error from chrome's network tab (not from your log)?
I'm hoping it will give more information send the headers and response sections (hoping it's something other than null)
Thats the strange thing the request is not getting logged in network tab at all, like its not even happening but console show the error.
will check again.
Try running the example client with your server and the example server with your client https://github.com/ronzeidman/ng2-ui-auth-example
any update?
Closing due to no update.
Hi,
i try to integrate this library and use in simple angular2 sample project
Tried facebook as provider, google as provider but same error
i guess http post call in exchangeForToken function return this error.
i any idea
client app custom config
onserver side i have /auth/google and /auth/facebook as post request which are going to do the rest stuff but i guess the whole process doesn't even reaching that part
for node server side i used the sample from (https://github.com/sahat/satellizer/tree/master/examples/server/node)