我已经在angular7中创建了一个应用程序,并尝试实现Google身份验证以使用Firebase登录,但是我遇到了一些问题。
我尝试了我熟悉的所有可能方法,但无法解决问题。我在这里附加我的代码,如果我做错了,请纠正我。
app.component.ts
import { LoginComponent } from './login/login.component';
import { BrowserModule } from '@angular/platform-browser';
import { NgModule, Component } from '@angular/core';
import { AngularFireModule } from 'angularfire2';
import { AngularFireDatabaseModule } from 'angularfire2/database';
import { AngularFireAuthModule } from 'angularfire2/auth';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { environment } from 'src/environments/environment';
import { NavbarComponent } from './navbar/navbar.component';
import { HomeComponent } from './home/home.component';
import { ProductsComponent } from './products/products.component';
import { ShoppingCartComponent } from './shopping-cart/shopping-cart.component';
import { CheckOutComponent } from './check-out/check-out.component';
import { OrderSuccessComponent } from './order-success/order-success.component';
import { MyOrdersComponent } from './my-orders/my-orders.component';
import { AdminProductsComponent } from './admin/admin-products/admin-products.component';
import { AdminOrdersComponent } from './admin/admin-orders/admin-orders.component';
import { RouterModule } from '@angular/router';
import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
import { NotFoundComponent } from './not-found/not-found.component';
@NgModule({
declarations: [
AppComponent,
NavbarComponent,
HomeComponent,
ProductsComponent,
ShoppingCartComponent,
CheckOutComponent,
OrderSuccessComponent,
MyOrdersComponent,
AdminProductsComponent,
AdminOrdersComponent,
LoginComponent,
NotFoundComponent
],
imports: [
BrowserModule,
AppRoutingModule,
AngularFireModule.initializeApp(environment.firebase),
AngularFireDatabaseModule,
AngularFireAuthModule,
NgbModule.forRoot(),
RouterModule.forRoot([
{
path : "",
component : HomeComponent
},
{
path : "productos",
component : ProductsComponent
},
{
path : "shopping-cart",
component : ShoppingCartComponent
},
{
path : 'check-out',
component : CheckOutComponent
},
{
path : 'order-success',
component : OrderSuccessComponent
},
{
path : 'login',
component : LoginComponent
},
{
path : 'my/orders',
component : MyOrdersComponent
},
{
path : 'admin/products',
component : AdminProductsComponent
},
{
path : 'admin/orders',
component : AdminOrdersComponent
},
{
path : '**',
component : NotFoundComponent
}
])
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
login.component.ts
import { Component, OnInit } from '@angular/core';
import * as firebase from 'firebase';
import { AngularFireAuth } from '@angular/fire/auth'; //angularfire2/auth
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent{
constructor(private afAuth : AngularFireAuth) { }
login()
{
this.afAuth.auth.signInWithRedirect(new firebase.auth.GoogleAuthProvider())
}
}
login.component.html
<button
(click) = "login()"
class = "btn btn-success">Login With Google
</button>