Skip to content

Commit

Permalink
social login
Browse files Browse the repository at this point in the history
  • Loading branch information
FredericHeem committed Jun 22, 2019
1 parent 26b61a9 commit b4c865f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 28 deletions.
2 changes: 1 addition & 1 deletion client/src/app.js
Expand Up @@ -12,7 +12,7 @@ const initialScreenFadeOut = () => {
}
}

export default async function({ context, parts, createRoutes, layout }) {
export default async function({ context, createRoutes, layout }) {
const routes = createRoutes({ context });
const router = Router({ context, routes, layout });

Expand Down
40 changes: 19 additions & 21 deletions client/src/parts/auth/authModule.js
Expand Up @@ -7,7 +7,7 @@ import registrationCompleteView from "./views/registrationCompleteView";
import { redirect } from "./authUtils";

export default function(context) {
const { rest } = context;
const { rest, history, config } = context;
const asyncOpCreate = AsyncOp(context);
const AsyncView = asyncView(context);

Expand All @@ -24,29 +24,24 @@ export default function(context) {
authStore.authenticated = false;
localStorage.removeItem("JWT");
},
preAuth: async () => {
redirectFromSocialLogin: async () => {
try {
await rest.get("me");
authStore.setAuthenticated();
const { pathname } = window.location;
//TODO FRED check
if (pathname === "auth/login") {
// From social login
redirect(context.history, config);
}
redirect(history, config);
} catch (errors) {
localStorage.removeItem("JWT");
authStore.reset();
}
}
})
});

function Stores() {
return {
auth: authStore,
logout: observable({
op: asyncOpCreate(() => rest.post("auth/logout")),
execute: action(async function() {
authStore.reset()
authStore.reset();
await this.op.fetch();
})
}),
Expand All @@ -73,16 +68,19 @@ export default function(context) {
children: [
{
path: "/login",
action: routerContext => ({
routerContext,
title: "Login",
component: (
<AsyncView
authStore={authStore}
getModule={() => import("./views/loginView")}
/>
)
})
action: async routerContext => {
await authStore.redirectFromSocialLogin();
return {
routerContext,
title: "Login",
component: (
<AsyncView
authStore={authStore}
getModule={() => import("./views/loginView")}
/>
)
};
}
},
{
path: "/register",
Expand Down
6 changes: 3 additions & 3 deletions client/src/parts/auth/components/mediaSigninButtons.js
Expand Up @@ -8,12 +8,12 @@ export default context => {
const socialAuthMap = {
facebook: {
label: `${tr.t("Sign in with")} Facebook`,
href: "api/v1/auth/facebook",
href: "/api/v1/auth/facebook",
icon: <img src={require("./icons/facebook.svg")} alt="facebook" width={20} />
},
google: {
label: `${tr.t("Sign in with")} Google`,
href: "api/v1/auth/google",
href: "/api/v1/auth/google",
icon: <img src={require("./icons/google.svg")} alt="google" width={20} />
},
fidor: {
Expand All @@ -22,7 +22,7 @@ export default context => {
},
crossbank: {
label: `${tr.t("Sign in with")} Open Bank`,
href: "api/v1/crossbank/login"
href: "/api/v1/crossbank/login"
}
};

Expand Down
Expand Up @@ -93,19 +93,19 @@ export default function AuthenticationRouter(app){
// Facebook Auth from web
router.get('/facebook', passport.authenticate('facebook', { scope: ['email'] }));
router.get('/facebook/callback',
passport.authenticate('facebook', { failureRedirect: '/login', successRedirect : '/login'}));
passport.authenticate('facebook', { failureRedirect: '/login', successRedirect : "back"}));
// Facebook Auth from mobile
router.post('/login_facebook', authHttpController.loginFacebook);

//Google
router.get('/google', passport.authenticate('google', { scope: ["email", "profile"] }));
router.get('/google/callback',
passport.authenticate('google', { failureRedirect: '/login', successRedirect : '/login'}));
passport.authenticate('google', { failureRedirect: '/login', successRedirect : "back"}));
router.post('/login_google', authHttpController.loginGoogle);

router.get('/fidor', passport.authenticate('fidor', { scope: ['email'] }));
router.get('/fidor/callback',
passport.authenticate('fidor', { failureRedirect: '/login', successRedirect : '/login'}));
passport.authenticate('fidor', { failureRedirect: '/login', successRedirect : "back"}));

app.server.baseRouter().mount('auth', router);

Expand Down

0 comments on commit b4c865f

Please sign in to comment.