Merge pull request #67 from Qolzam/pr/66
[Update Package] Update firebase to version 5.*
This commit is contained in:
@@ -23,22 +23,22 @@ export class AuthorizeService implements IAuthorizeService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Login the user
|
* Login the user
|
||||||
*
|
|
||||||
* @returns {Promise<LoginUser>}
|
|
||||||
* @memberof IAuthorizeService
|
|
||||||
*/
|
*/
|
||||||
public login: (email: string, password: string) => Promise<LoginUser> = (email, password) => {
|
public async login(email: string, password: string) {
|
||||||
|
try {
|
||||||
return new Promise<LoginUser>((resolve, reject) => {
|
const result = await firebaseAuth()
|
||||||
firebaseAuth()
|
|
||||||
.signInWithEmailAndPassword(email, password)
|
.signInWithEmailAndPassword(email, password)
|
||||||
.then((result) => {
|
const {user} = result
|
||||||
resolve(new LoginUser(result.uid, result.emailVerified))
|
if (user) {
|
||||||
})
|
return new LoginUser(user.uid, user.emailVerified)
|
||||||
.catch((error: any) => {
|
|
||||||
reject(new SocialError(error.code, error.message))
|
} else {
|
||||||
})
|
throw new SocialError('AuthorizeService/login', 'User object is empty!')
|
||||||
})
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
throw new SocialError(error.code, error.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,20 +63,24 @@ export class AuthorizeService implements IAuthorizeService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a user
|
* Register a user
|
||||||
*
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
* @memberof IAuthorizeService
|
|
||||||
*/
|
*/
|
||||||
public registerUser: (user: User) => Promise<RegisterUserResult> = (user) => {
|
public async registerUser(registerUser: User) {
|
||||||
return new Promise<RegisterUserResult>((resolve, reject) => {
|
try {
|
||||||
firebaseAuth()
|
const result = await firebaseAuth()
|
||||||
.createUserWithEmailAndPassword(user.email as string, user.password as string)
|
.createUserWithEmailAndPassword(registerUser.email as string, registerUser.password as string)
|
||||||
.then((signupResult) => {
|
const {user} = result
|
||||||
const {uid, email} = signupResult
|
if (user) {
|
||||||
this.storeUserInformation(uid,email,user.fullName,'').then(resolve)
|
const { uid, email } = user
|
||||||
})
|
const registerResult = await this.storeUserInformation(uid, email!, registerUser.fullName, '')
|
||||||
.catch((error: any) => reject(new SocialError(error.code, error.message)))
|
return registerResult
|
||||||
})
|
|
||||||
|
} else {
|
||||||
|
throw new SocialError('AuthorizeService/login', 'User object is empty!')
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
throw new SocialError(error.code, error.message)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -182,16 +186,15 @@ export class AuthorizeService implements IAuthorizeService {
|
|||||||
throw new SocialError('authorizeService/loginWithOAuth', 'None of OAuth type is matched!')
|
throw new SocialError('authorizeService/loginWithOAuth', 'None of OAuth type is matched!')
|
||||||
}
|
}
|
||||||
firebaseAuth().signInWithPopup(provider).then((result) => {
|
firebaseAuth().signInWithPopup(provider).then((result) => {
|
||||||
// This gives you a GitHub Access Token. You can use it to access the GitHub API.
|
|
||||||
let token = result.credential.accessToken
|
|
||||||
// The signed-in user info.
|
// The signed-in user info.
|
||||||
const {user} = result
|
const user = result.user!
|
||||||
const { credential } = result
|
const { credential } = result
|
||||||
const { uid, displayName, email, photoURL } = user
|
const { uid, displayName, email, photoURL } = user
|
||||||
const {accessToken, providerId} = credential
|
const { providerId } = credential!
|
||||||
this.storeUserProviderData(uid,email,displayName,photoURL,providerId,accessToken)
|
this.storeUserProviderData(uid, email!, displayName!, photoURL!, providerId, 'No Access token provided!')
|
||||||
// this.storeUserInformation(uid,email,displayName,photoURL).then(resolve)
|
// this.storeUserInformation(uid,email,displayName,photoURL).then(resolve)
|
||||||
resolve(new LoginUser(user.uid,true,providerId,displayName,email,photoURL))
|
resolve(new LoginUser(user.uid, true, providerId, displayName!, email!, photoURL!))
|
||||||
|
|
||||||
}).catch(function (error: any) {
|
}).catch(function (error: any) {
|
||||||
// Handle Errors here.
|
// Handle Errors here.
|
||||||
|
|||||||
Reference in New Issue
Block a user