Created
January 9, 2018 09:52
-
-
Save jayserdny/f13b5f8c15b75550706e76ac453d3431 to your computer and use it in GitHub Desktop.
Auth provider for steemit tutorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { Accounts } from 'meteor/accounts-base'; | |
import { Meteor } from 'meteor/meteor'; | |
@Injectable() | |
export class AuthProvider { | |
constructor() { | |
console.log('Hello AuthProvider Provider'); | |
} | |
/** | |
* | |
* Method to login using email and password. | |
* | |
* @param {string} email: Email of the user trying to login. | |
* @param {string} password: Password of the user to login. | |
* | |
*/ | |
login(email: string, password: string): Promise<void> { | |
return new Promise<void>((resolve, reject) => { | |
Meteor.loginWithPassword(email, password, (e: Error) => { | |
if (e) return reject(e); | |
resolve(); | |
}); | |
}); | |
} | |
/** | |
* | |
* Method to register new user | |
* | |
* @param {string} email: Email of the user trying to login. | |
* @param {string} password: Password of the user to login. | |
* @param {string} username: Username of the user. | |
* @param {string} name: Name of the user, | |
* | |
*/ | |
register(email: string, password: string, username: string, name: string): Promise<void> { | |
let userData = { | |
username: username, | |
email: email, | |
password: password, | |
profile: { | |
name: name | |
} | |
}; | |
return new Promise<void>((resolve, reject) => { | |
Accounts.createUser(userData, (e: Error) => { | |
if (e) return reject(e); | |
resolve(); | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment