mirror of
https://github.com/wassname/talk.git
synced 2026-08-17 11:27:52 +08:00
Ádding Traslations and Same Origin Requests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import * as actions from '../constants/auth';
|
||||
import {base, handleResp} from '../helpers';
|
||||
import {base, handleResp, getInit} from '../helpers';
|
||||
|
||||
export const loginFacebook = () => dispatch => {
|
||||
dispatch(loginFacebookRequest());
|
||||
@@ -30,10 +30,7 @@ export const loginFacebookCallback = (err, data) => {
|
||||
|
||||
export const logout = () => dispatch => {
|
||||
dispatch(logoutRequest());
|
||||
fetch(`${base}/api/v1/auth`, {
|
||||
method: 'DELETE',
|
||||
credentials: 'same-origin'
|
||||
})
|
||||
fetch(`${base}/auth`, getInit('DELETE'))
|
||||
.then(handleResp)
|
||||
.then(() => dispatch(dispatch(logoutSuccess())))
|
||||
.catch(error => dispatch(logoutFailure(error)));
|
||||
@@ -44,7 +41,7 @@ const logoutRequest = () => ({
|
||||
});
|
||||
|
||||
const logoutSuccess = () => ({
|
||||
type: actions.USER_LOGOUT_SUCCESS
|
||||
type: actions.USER_LOGOUT_SUCCESS,
|
||||
});
|
||||
|
||||
const logoutFailure = (error) => ({
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
export const base = '/api/v1';
|
||||
|
||||
export const getInit = (method, body) => {
|
||||
const headers = new Headers({
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json'
|
||||
});
|
||||
let init = {
|
||||
method,
|
||||
headers: new Headers({
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json'
|
||||
}),
|
||||
credentials: 'same-origin'
|
||||
};
|
||||
|
||||
const init = {method, headers};
|
||||
if (method.toLowerCase() !== 'get') {
|
||||
init.body = JSON.stringify(body);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
import React from 'react';
|
||||
import Button from './Button';
|
||||
import I18n from 'coral-framework/modules/i18n/i18n';
|
||||
import translations from '../translations';
|
||||
|
||||
const lang = new I18n(translations);
|
||||
|
||||
const SignIn = ({openFacebookWindow, logout}) => (
|
||||
<div>
|
||||
<Button type="facebook" onClick={openFacebookWindow}>
|
||||
Continue with Facebook
|
||||
{lang.t('signIn.facebookLogin')}
|
||||
</Button>
|
||||
<a onClick={logout}>
|
||||
Logout
|
||||
{lang.t('signIn.logout')}
|
||||
</a>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
export default {
|
||||
en: {
|
||||
'signIn': {
|
||||
facebookLogin: 'Continue with Facebook',
|
||||
logout: 'Logout'
|
||||
}
|
||||
},
|
||||
es: {
|
||||
'signIn': {
|
||||
facebookLogin: 'Continuar con Facebook',
|
||||
logout: 'Salir'
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user