+
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smooth-jokes-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@reactioncommerce/api-plugin-authentication": minor
---

Add accounts js env var configuration (jwt expiration time comfig, returnTokensAfterResetPassword config)
5 changes: 4 additions & 1 deletion packages/api-plugin-authentication/src/config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import envalid from "envalid";

const { str } = envalid;
const { str, bool } = envalid;

export default envalid.cleanEnv(
process.env,
{
ACCOUNTS_JS_RETURN_TOKENS_AFTER_RESET_PASSWORD: bool({ default: false }),
ACCOUNTS_JS_ACCESS_TOKEN_EXPIRES_IN: str({ default: "90m" }),
ACCOUNTS_JS_REFRESH_TOKEN_EXPIRES_IN: str({ default: "30d" }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are providing 30d as default for refresh-token, but the default in accountsjs is 7d link

PASSWORD_RESET_PATH_FRAGMENT: str({ default: "?resetToken=" }),
STORE_URL: str({ devDefault: "http://localhost:4000" }),
TOKEN_SECRET: str({ default: "UPDATE_THIS_SECRET" })
Expand Down
22 changes: 20 additions & 2 deletions packages/api-plugin-authentication/src/util/accountServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ export default async (app) => {
if (accountsServer && accountsGraphQL) {
return { accountsServer, accountsGraphQL };
}
const { MONGO_URL, PASSWORD_RESET_PATH_FRAGMENT, STORE_URL, TOKEN_SECRET } = config;
const {
ACCOUNTS_JS_RETURN_TOKENS_AFTER_RESET_PASSWORD,
ACCOUNTS_JS_ACCESS_TOKEN_EXPIRES_IN,
ACCOUNTS_JS_REFRESH_TOKEN_EXPIRES_IN,
MONGO_URL,
PASSWORD_RESET_PATH_FRAGMENT,
STORE_URL,
TOKEN_SECRET
} = config;
const { context } = app;

const client = await mongoConnectWithRetry(MONGO_URL);
Expand All @@ -26,12 +34,22 @@ export default async (app) => {
idProvider: () => mongoose.Types.ObjectId().toString()
});

const password = new AccountsPassword();
const password = new AccountsPassword({
returnTokensAfterResetPassword: ACCOUNTS_JS_RETURN_TOKENS_AFTER_RESET_PASSWORD
});

accountsServer = new AccountsServer(
{
siteUrl: STORE_URL,
tokenSecret: TOKEN_SECRET,
tokenConfigs: {
accessToken: {
expiresIn: ACCOUNTS_JS_ACCESS_TOKEN_EXPIRES_IN
},
refreshToken: {
expiresIn: ACCOUNTS_JS_REFRESH_TOKEN_EXPIRES_IN
}
},
db: accountsMongo,
enableAutologin: true,
ambiguousErrorMessages: false,
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载