简体   繁体   English

如何使用angular进行angular-social-auth

[英]How to make angular-social-auth using angular

I'm angular2-social-auth, in project with angular 5, but it gives me an error heres the code : 我是angular2-social-auth,在带有angular 5的项目中,但是这里的代码给我一个错误:

Module.ts 模块

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';


import { AppComponent } from './app.component';
import { Angular2SocialLoginModule } from "angular2-social-auth";

let providers = {
  /* "google": {
  "clientId": "GOOGLE_CLIENT_ID"
},
"linkedin": {
  "clientId": "LINKEDIN_CLIENT_ID"
 },*/
"facebook": {
   "clientId": "MyGeneratedCode",
   "apiVersion": "v2.11" //like v2.4
 }

}; };

@NgModule({
 declarations: [
  AppComponent
   ],
imports: [
 BrowserModule,
  Angular2SocialLoginModule
],
 providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Angular2SocialLoginModule.loadProvidersScripts(providers);

component.ts : component.ts:

import { Component, OnDestroy } from '@angular/core';
import { AuthService } from "angular2-social-auth";

@Component({
 selector: 'app-root',
 templateUrl: './app.component.html',
 styleUrls: ['./app.component.css']
 })
 export class AppComponent  implements OnDestroy {

 title = 'app';

  constructor(public _auth: AuthService){ }

 signIn(provider){
 this._auth.login(provider).subscribe(
   (data) => {
               console.log(data);
               //user data
               //first_name, last_name, image, uid, provider, email, token     (returns  accessToken for Facebook and Google no token for linkedIn)
             }
 )

} }

 logout(){
   this._auth.logout().subscribe(
   (data)=>{
     //return a boolean value.
    }
  )
 }

} }

html : html:

<h1>
 Sign in
</h1>

<button (click)="socialSignIn('facebook')">Sign in with Facebook</button>
<button (click)="socialSignIn('google')">Signin in with Google</button>   

I did just what the documentation told me, can any one help please? 我只是按照文档告诉我的,可以帮忙吗? when i clic the facebook button it gives me this error : 当我点击facebook按钮时,它给了我这个错误:

TypeError: _co.socialSignIn is not a function Stack trace: View_AppComponent_0/<@ng:///AppModule/AppComponent.ngfactory.js:14:19 handleEvent@webpack-internal:///../../../core/esm5/core.js:13745:115 TypeError:_co.socialSignIn不是函数堆栈跟踪:View_AppComponent_0 / <@ng:///AppModule/AppComponent.ngfactory.js:14:19 handleEvent @ webpack-internal:///../../../核心/ ESM5 /核心.js:13745:115

You try calling a function called "socialSignIn" in your html, however i don't see this function in your code. 您尝试在html中调用一个名为“ socialSignIn”的函数,但是我在您的代码中看不到该函数。 So error message is clear : socialSignIn is not a function 所以错误消息很清楚: socialSignIn is not a function

Try call signIn('facebook') instead 尝试致电signIn('facebook')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Django REST Social Auth中使用Angular 5? - How to use Angular 5 with Django REST Social Auth? 使用Cookie的Angular 6身份验证 - Angular 6 auth using cookies 使用 Passport 进行社交身份验证登录后如何重定向到个人资料页面? (角度,快递,护照,jwt) - How to redirect to profile page after social auth login with Passport ? (Angular, express, passport, jwt) 如何使用 Angular 在社交网站中共享自定义文本 - How to share Custom Text in social website using Angular 使用Angular 6的Cognito Facebook社交登录:如何使用返回的代码在放大Auth中验证用户身份 - Cognito Facebook social login with Angular 6: How to use returned code to authenticate user in amplify Auth 如何使用angular进行HTTP基本身份验证 - How to do HTTP Basic Auth using angular 如何使用 angular 和 spring boot 添加社交登录功能 - How to add social login functionality using angular and spring boot 如何使用 Angular 材料(如 Angular.io/resources 网站)插入社交图标? - How to insert social icons using Angular Material like the Angular.io/resources site? 使用护照js和角度2的社会认证 - Social authentication using passports js and angular 2 Angular 8 中使用 Reactive Forms 的动态社交链接 - Dynamic social links in Angular 8 using Reactive Forms
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM