Skip to content

Include options for signIn #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/core/gapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ function _formatUser (guser) {
}
}

/** Get the response object from the user's auth session. */
function _formatAuthObject (guser) {
if (!guser.getAuthResponse) return null
return guser.getAuthResponse()
}

export default class GAPI {
/**
* The constructor expect as parameter the config object, containing
Expand Down Expand Up @@ -130,9 +136,16 @@ export default class GAPI {
})
}

/** returns asynchronously true if the user is signed in */
/** returns the current user auth data if signed in, undefined otherwise */
getAuthObject () {
return this._libraryInit('auth2')
.then(auth => {
if (auth.isSignedIn.get()) {
return Promise.resolve(_formatAuthObject(auth.currentUser.get()))
} else {
return Promise.resolve(null)
}
})
}

/** returns the current user if signed in, undefined otherwise */
Expand All @@ -149,13 +162,13 @@ export default class GAPI {

/** Starts the signin process - returns a promise resolved with the user if
* signin successfull, or rejected otherwise */
signIn () {
signIn (options) {
return this._libraryInit('auth2')
.then(auth => {
if (auth.isSignedIn.get()) {
return Promise.resolve(_formatUser(auth.currentUser.get()))
} else {
return auth.signIn()
return auth.signIn(options)
.then(guser => {
return Promise.resolve(_formatUser(guser))
})
Expand Down