import * as fetch from "isomorphic-fetch"; import { StyleRoot } from "radium"; import * as React from "react"; import { authSetupWithDefaults } from "../../helpers/"; import AuthModal from "../authModal"; const { Component } = React; export interface ILoginState { isOpen: boolean; authActions: any; } export default class GlobalLogin extends React.Component<{}, ILoginState> { public state: ILoginState; constructor(props) { super(props); this.state = { authActions: {}, isOpen: false, }; this.close = this.close.bind(this); } public componentDidMount() { window.addEventListener("hashchange", () => { this.setState({ isOpen: this.isOpen(), }); }, false); const authLinks = authSetupWithDefaults(window.lp.auth); this.setState({ authActions: { facebook: () => { window.location.href = authLinks.facebookLink; }, twitter: () => { window.location.href = authLinks.twitterLink; }, google: () => { window.location.href = authLinks.googleLink; }, passwordless: (email) => { const magicLink = authLinks.passwordlessLink(email); fetch(magicLink, { method: "post", credentials: "include", }); }, password: authLinks.passwordLink, }, isOpen: this.isOpen(), }); } public isOpen() { return typeof window !== "undefined" && window.location.hash.indexOf("login") === 1; } public close() { window.location.hash = ""; } public render() { return ( {this.state.isOpen && } ); } }