Skip to content

Commit

Permalink
Add signin/up info in auth URL generated by passport
Browse files Browse the repository at this point in the history
  • Loading branch information
impactmass committed Sep 20, 2018
1 parent 31cd803 commit d9579d3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/components/AccountDropdown/AccountDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ class AccountDropdown extends Component {
:
<Fragment>
<div className={classes.authContent}>
<Button color="primary" fullWidth href="/auth2" variant="raised">
<Button color="primary" fullWidth href="/signin" variant="raised">
Sign In
</Button>
</div>
<Button color="primary" fullWidth href="/auth2">
<Button color="primary" fullWidth href="/signup">
Create Account
</Button>
</Fragment>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Entry/Entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ export default class Entry extends Component {

static defaultProps = {
onLoginButtonClick() {
Router.pushRoute("/auth2");
Router.pushRoute("/signin");
},
onRegisterButtonClick() {
Router.pushRoute("/auth2");
Router.pushRoute("/signup");
},
setEmailOnAnonymousCart() {}
};
Expand Down
16 changes: 13 additions & 3 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import router from "./routes";
const app = nextApp({ dir: appPath, dev });
const routeHandler = router.getRequestHandler(app);

// This is needed to allow custom parameters e.g loginActions to be included
// when requesting authorization.
OAuth2Strategy.prototype.authorizationParams = function (options) {
return options || {};
};

useStaticRendering(true);

passport.use("oauth2", new OAuth2Strategy({
Expand Down Expand Up @@ -46,11 +52,15 @@ app
server.use(passport.session());
server.use(cookieParser());

// This endpoint initializes the OAuth2 request
server.get("/auth2", (req, res, next) => {
server.get("/signin", (req, res, next) => {
if (!req.user) req.session.redirectTo = req.get("Referer");
next();
}, passport.authenticate("oauth2", { loginAction: "signin" }));

server.get("/signup", (req, res, next) => {
if (!req.user) req.session.redirectTo = req.get("Referer");
next();
}, passport.authenticate("oauth2"));
}, passport.authenticate("oauth2", { loginAction: "signup" }));

// This endpoint handles OAuth2 requests (exchanges code for token)
server.get("/callback", passport.authenticate("oauth2"), (req, res) => {
Expand Down

0 comments on commit d9579d3

Please sign in to comment.