Telegram auth (wip)
This commit is contained in:
parent
5fe60d20d3
commit
58c54e5b94
7 changed files with 92 additions and 9 deletions
48
imports/ui/pages/Auth/Auth.js
Normal file
48
imports/ui/pages/Auth/Auth.js
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/* eslint-disable react/jsx-indent-props */
|
||||
/* eslint-disable import/no-absolute-path */
|
||||
/* eslint-disable import/no-absolute-path */
|
||||
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { translate } from 'react-i18next';
|
||||
import { Bert } from 'meteor/themeteorchef:bert';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { T9n } from 'meteor-accounts-t9n';
|
||||
import { Accounts } from 'meteor/accounts-base';
|
||||
|
||||
class Auth extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
const { token } = props.match.params;
|
||||
// console.log(token);
|
||||
console.log(Meteor.connection);
|
||||
console.log(Accounts.connection);
|
||||
|
||||
Meteor.loginWithToken(token, (error) => {
|
||||
// this is going to throw error if we logged out
|
||||
if (error) {
|
||||
Bert.alert(T9n.get(`error.accounts.${error.reason}`), 'danger');
|
||||
// props.history.push('/login');
|
||||
} else {
|
||||
console.log('loginWithToken');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div />
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Auth.propTypes = {
|
||||
// t: PropTypes.func.isRequired,
|
||||
history: PropTypes.object.isRequired,
|
||||
match: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
Auth.defaultProps = {
|
||||
};
|
||||
|
||||
export default translate([], { wait: true })(Auth);
|
||||
|
|
@ -8,7 +8,6 @@ import { Link } from 'react-router-dom';
|
|||
import { Meteor } from 'meteor/meteor';
|
||||
import { Accounts } from 'meteor/accounts-base';
|
||||
import { Bert } from 'meteor/themeteorchef:bert';
|
||||
import randomHex from 'crypto-random-hex';
|
||||
import Icon from '../../components/Icon/Icon';
|
||||
import OAuthLoginButtons from '../../components/OAuthLoginButtons/OAuthLoginButtons';
|
||||
import InputHint from '../../components/InputHint/InputHint';
|
||||
|
|
@ -96,6 +95,26 @@ class Signup extends React.Component {
|
|||
this.setState({ termsAccept });
|
||||
}
|
||||
|
||||
onTelegramAuth() {
|
||||
/* dynamic import sample
|
||||
// https://github.com/meteor/meteor/issues/9038
|
||||
import('crypto-random-hex').then(({ default: randomHex }) => {
|
||||
// console.log(randomHex);
|
||||
const hex = randomHex(20);
|
||||
window.open(`https://t.me/TodosContraElFuego_bot?start=${hex}`);
|
||||
}); */
|
||||
Meteor.call('auth.getHash', (error, response) => {
|
||||
if (error) {
|
||||
console.warn(error);
|
||||
} else {
|
||||
const bot = Meteor.isDevelopment ? 'rednodetest_bot' : 'TodosContraElFuego_bot';
|
||||
const url = `https://t.me/${bot}?start=${response}`;
|
||||
// console.log(url);
|
||||
window.open(url);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
const { t, history } = this.props;
|
||||
return (<div className="Signup">
|
||||
|
|
@ -103,12 +122,12 @@ class Signup extends React.Component {
|
|||
<Col xs={12} sm={6} md={5} lg={4}>
|
||||
<h4 className="page-header">{t('Registrarse')}</h4>
|
||||
<Row>
|
||||
{ false && // disabled
|
||||
{ Meteor.settings.public.telegramAuth &&
|
||||
<Col xs={12}>
|
||||
<button
|
||||
className="btn btn-block btn-raised btn-primary OAuthLoginButtonDis OAuthLoginButton-telegram"
|
||||
type="button"
|
||||
onClick={() => { const hex = randomHex(20); console.log(hex); window.open(`https://t.me/TodosContraElFuego_bot?start=${hex}`); }}
|
||||
onClick={this.onTelegramAuth}
|
||||
>
|
||||
<span><Icon icon="telegram" /> {t('Iniciar sesión con Telegram')}</span>
|
||||
</button>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue