Skip to content

Commit

Permalink
Merge pull request #39 from Holo-Host/exit-login-B-04330
Browse files Browse the repository at this point in the history
Implement cancellable option and back button interception [B-04330]
  • Loading branch information
timotree3 authored Jul 2, 2021
2 parents 68e54dd + e5e9f8a commit e9381c4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,18 @@ Returns `{
url: string
}`

### `.signIn() -> Promise<boolean>`
### `.signIn( opts? ) -> Promise<boolean>`
Trigger Chaperone's sign-in prompt.

If `opts.cancellable`, then the prompt can be exited to remain anonymous. Default = `true`.

> **WARNING:** This will throw an error if the context is `Connection.AUTONOMOUS`.
### `.signUp() -> Promise<boolean>`
### `.signUp( opts? ) -> Promise<boolean>`
Trigger Chaperone's sign-up prompt.

If `opts.cancellable`, then the prompt can be exited to remain anonymous. Default = `true`.

> **WARNING:** This will throw an error if the context is `Connection.AUTONOMOUS`.
### `.signOut() -> Promise<boolean>`
Expand Down
40 changes: 34 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ class Connection extends EventEmitter {
style.top = "0";
style.left = "0";
style.display = "none";

window.addEventListener('popstate', (event) => {
if (event.state === "_web_sdk_shown") {
history.back()
} else {
this.iframe.style.display = "none"
}
})
}

async context() {
Expand All @@ -101,17 +109,37 @@ class Connection extends EventEmitter {
return response;
}

async signUp() {
async signUp(opts) {
const { cancellable = true } = opts || {}
if (cancellable) {
history.pushState("_web_sdk_shown", "")
}
this.iframe.style.display = "block";
const result = await this.child.call("signUp");
this.iframe.style.display = "none";
const result = await this.child.call("signUp", opts);
if (cancellable) {
if (history.state === "_web_sdk_shown") {
history.back()
}
} else {
this.iframe.style.display = "none";
}
return result;
}

async signIn() {
async signIn(opts) {
const { cancellable = true } = opts || {}
if (cancellable) {
history.pushState("_web_sdk_shown", "")
}
this.iframe.style.display = "block";
const result = await this.child.call("signIn");
this.iframe.style.display = "none";
const result = await this.child.call("signIn", opts);
if (cancellable) {
if (history.state === "_web_sdk_shown") {
history.back()
}
} else {
this.iframe.style.display = "none";
}
return result;
}

Expand Down

0 comments on commit e9381c4

Please sign in to comment.