Skip to content

Commit 84452ce

Browse files
committed
feat: implement change password flow
Signed-off-by: Eric Dobbertin <[email protected]>
1 parent d440385 commit 84452ce

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ OAUTH2_AUTH_URL=http://localhost:4444/oauth2/auth
88
OAUTH2_CLIENT_ID=example-storefront
99
OAUTH2_CLIENT_SECRET=CHANGEME
1010
OAUTH2_HOST=hydra.auth.reaction.localhost
11+
OAUTH2_IDP_PUBLIC_CHANGE_PASSWORD_URL=http://localhost:4100/account/change-password?email=EMAIL&from=FROM
1112
OAUTH2_IDP_HOST_URL=http://identity.auth.reaction.localhost:4100
1213
OAUTH2_REDIRECT_URL=http://localhost:4000/callback
1314
OAUTH2_TOKEN_URL=http://hydra.auth.reaction.localhost:4444/oauth2/token

src/components/AccountDropdown/AccountDropdown.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ class AccountDropdown extends Component {
7878
Profile
7979
</Button>
8080
</div>
81+
<div className={classes.marginBottom}>
82+
<Button color="primary" fullWidth href={`/change-password?email=${encodeURIComponent(account.emailRecords[0].address)}`}>
83+
Change Password
84+
</Button>
85+
</div>
8186
<Button color="primary" fullWidth href={`/logout/${account._id}`} variant="contained">
8287
Sign Out
8388
</Button>

src/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ if (process.env.IS_BUILDING_NEXTJS) {
3737
OAUTH2_AUTH_URL: url(),
3838
OAUTH2_CLIENT_ID: str(),
3939
OAUTH2_CLIENT_SECRET: str(),
40+
OAUTH2_IDP_PUBLIC_CHANGE_PASSWORD_URL: url(),
4041
OAUTH2_IDP_HOST_URL: url(),
4142
OAUTH2_REDIRECT_URL: url(),
4243
OAUTH2_TOKEN_URL: url(),

src/serverAuth.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,21 @@ function configureAuthForServer(server) {
7474
res.redirect(req.session.redirectTo || "/");
7575
});
7676

77+
server.get("/change-password", (req, res) => {
78+
const { email } = req.query;
79+
80+
let from = req.get("Referer");
81+
if (typeof from !== "string" || from.length === 0) {
82+
from = config.CANONICAL_URL;
83+
}
84+
85+
let url = config.OAUTH2_IDP_PUBLIC_CHANGE_PASSWORD_URL;
86+
url = url.replace("EMAIL", encodeURIComponent(email || ""));
87+
url = url.replace("FROM", encodeURIComponent(from));
88+
89+
res.redirect(url);
90+
});
91+
7792
server.get("/logout/:userId", (req, res, next) => {
7893
const { userId } = req.params;
7994
if (!userId) {

0 commit comments

Comments
 (0)