Last active
July 21, 2018 16:52
-
-
Save funador/450467e720a7ed55bbfb28e8776dc211 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| export default class App extends Component { | |
| // previously written lifecycle methods | |
| // .... | |
| // Routinely checks the popup to re-enable the login button | |
| // if the user closes the popup without authenticating. | |
| checkPopup() { | |
| const check = setInterval(() => { | |
| const { popup } = this | |
| if (!popup || popup.closed || popup.closed === undefined) { | |
| clearInterval(check) | |
| this.setState({ disabled: ''}) | |
| } | |
| }, 1000) | |
| } | |
| // Launches the popup on the server and passes along the socket id so it | |
| // can be used to send back user data to the appropriate socket on | |
| // the connected client. | |
| openPopup() { | |
| const width = 600, height = 600 | |
| const left = (window.innerWidth / 2) - (width / 2) | |
| const top = (window.innerHeight / 2) - (height / 2) | |
| const url = `${API_URL}/twitter?socketId=${socket.id}` | |
| return window.open(url, '', | |
| `toolbar=no, location=no, directories=no, status=no, menubar=no, | |
| scrollbars=no, resizable=no, copyhistory=no, width=${width}, | |
| height=${height}, top=${top}, left=${left}` | |
| ) | |
| } | |
| // Kicks off the processes of opening the popup on the server and listening | |
| // to the popup. It also disables the login button so the user can not | |
| // attempt to login to the provider twice. | |
| startAuth() { | |
| if (!this.state.disabled) { | |
| this.popup = this.openPopup() | |
| this.checkPopup() | |
| this.setState({disabled: 'disabled'}) | |
| } | |
| } | |
| closeCard() { | |
| this.setState({user: {}}) | |
| } | |
| // missing render method | |
| // ... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment