Skip to content

Commit

Permalink
fix: register
Browse files Browse the repository at this point in the history
  • Loading branch information
lionelB committed Jun 4, 2020
1 parent e2d40cd commit ee0cecb
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ JWT_TOKEN_EXPIRES=15
REFRESH_TOKEN_EXPIRES=43200

# Activation token lifetime (7 days in minutes)
ACTIVATION_TOKEN_EXPIRES=10080
NEXT_PUBLIC_ACTIVATION_TOKEN_EXPIRES=10080

# Email
ACCOUNT_MAIL_SENDER=[email protected]
4 changes: 3 additions & 1 deletion src/pages/api/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ export default async function login(req, res) {
.query(refreshTokenMutation, {
refresh_token_data: {
user_id: user.id,
expires_at: getExpiryDate(process.env.REFRESH_TOKEN_EXPIRES || 43200),
expires_at: getExpiryDate(
parseInt(process.env.REFRESH_TOKEN_EXPIRES, 10)
),
},
})
.toPromise();
Expand Down
12 changes: 3 additions & 9 deletions src/pages/api/refresh_token.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,15 @@ export default async function refreshToken(req, res) {
});

try {
console.log("[ /api/refrehs_token ] update new token", {
user_id: user.id,
refresh_token: new_refresh_token,
REFRESH_TOKEN_EXPIRES: process.env.REFRESH_TOKEN_EXPIRES,
JWT_TOKEN_EXPIRES: process.env.JWT_TOKEN_EXPIRES,
ACTIVATION_TOKEN_EXPIRES: process.env.ACTIVATION_TOKEN_EXPIRES,
expires_at: getExpiryDate(process.env.REFRESH_TOKEN_EXPIRES),
});
await client
.query(deletePreviousRefreshTokenMutation, {
old_refresh_token: refresh_token,
new_refresh_token_data: {
user_id: user.id,
refresh_token: new_refresh_token,
expires_at: getExpiryDate(process.env.REFRESH_TOKEN_EXPIRES),
expires_at: getExpiryDate(
parseInt(process.env.REFRESH_TOKEN_EXPIRES, 10)
),
},
})
.toPromise();
Expand Down
74 changes: 0 additions & 74 deletions src/pages/api/register.js

This file was deleted.

4 changes: 3 additions & 1 deletion src/pages/api/reset_password.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export default async function reset_password(req, res) {
.query(udpateSecretTokenMutation, {
email,
secret_token: uuidv4(),
expires: getExpiryDate(process.env.ACTIVATION_TOKEN_EXPIRES || 10080),
expires: getExpiryDate(
parseInt(process.env.NEXT_PUBLIC_ACTIVATION_TOKEN_EXPIRES, 10)
),
})
.toPromise();
if (result.error) {
Expand Down
4 changes: 4 additions & 0 deletions src/pages/user/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ function prepareMutationData(input) {
return {
user: {
...input,
secret_token_expires_at: parseInt(
process.env.NEXT_PUBLIC_REFRESH_TOKEN_EXPIRES,
10
),
user_roles: { data: { role: input.default_role } },
},
};
Expand Down

0 comments on commit ee0cecb

Please sign in to comment.