Ádding Traslations and Same Origin Requests

This commit is contained in:
Belen Curcio
2016-11-11 22:38:15 -03:00
parent 103acd4bce
commit 984b2acac4
4 changed files with 31 additions and 13 deletions
+3 -6
View File
@@ -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) => ({
+8 -5
View File
@@ -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);
}
+6 -2
View File
@@ -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>
);
+14
View File
@@ -0,0 +1,14 @@
export default {
en: {
'signIn': {
facebookLogin: 'Continue with Facebook',
logout: 'Logout'
}
},
es: {
'signIn': {
facebookLogin: 'Continuar con Facebook',
logout: 'Salir'
}
}
};