-
Create new identity pool
-
Registration Facebook for Developers and create facebook app.
-
Install ng2-cognito-sync
npm install ng2-cognito-sync --save
-
Import Ng2CognitoSyncModule
import { Ng2CognitoSyncModule } from 'ng2-cognito-sync'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, FormsModule, HttpModule, Ng2CognitoSyncModule.forRoot({ region: 'ap-northeast-1', identityCredentials: { IdentityPoolId: 'ap-northeast-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' }, facebookInitParams: { appId: '000000000000000' } }) ],
-
Usage
<button (click)="login()">Login</button>
import { Ng2CognitoSync } from 'ng2-cognito-sync';
constructor(private cognitoSync: Ng2CognitoSync) { } login() { this.cognitoSync.facebook.login('name,gender,birthday,locale', {scope: 'public_profile,user_birthday', return_scopes: true}).subscribe(res => { if (res.profile) { this.cognitoSync.facebook.openDataset('user').subscribe(dataset => { dataset.put('profile', JSON.stringify(res.profile), (errPut, record) => { dataset.synchronize(); }); }); } }, error => { console.error(error); }); }