propro-utils 1.4.80 → 1.4.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/server/index.js +14 -11
package/package.json
CHANGED
package/src/server/index.js
CHANGED
|
@@ -48,8 +48,8 @@ class AuthMiddleware {
|
|
|
48
48
|
|
|
49
49
|
initializeRoutes() {
|
|
50
50
|
this.router.post('/api/auth', this.handleAuth);
|
|
51
|
-
this.router.
|
|
52
|
-
this.router.
|
|
51
|
+
this.router.post('/api/login', this.handleLogin);
|
|
52
|
+
this.router.post('/api/register', this.handleRegister);
|
|
53
53
|
this.router.get('/api/callback', this.handleCallback);
|
|
54
54
|
this.router.post('/api/refreshToken', this.handleRefreshToken);
|
|
55
55
|
this.router.post('/api/logout', this.handleLogout);
|
|
@@ -77,7 +77,7 @@ class AuthMiddleware {
|
|
|
77
77
|
try {
|
|
78
78
|
const response = await this.proxyToAuthServer(
|
|
79
79
|
req,
|
|
80
|
-
|
|
80
|
+
`/api/v1/auth/login?returnTokens=${returnTokens}`,
|
|
81
81
|
'POST',
|
|
82
82
|
{
|
|
83
83
|
email,
|
|
@@ -89,11 +89,11 @@ class AuthMiddleware {
|
|
|
89
89
|
}
|
|
90
90
|
);
|
|
91
91
|
|
|
92
|
-
const { account } = response.data;
|
|
92
|
+
const { account, tokens } = response.data;
|
|
93
93
|
const user = await checkIfUserExists(this.userSchema, account.accountId);
|
|
94
94
|
|
|
95
95
|
if (returnTokens === 'true') {
|
|
96
|
-
res.status(response.status).json(
|
|
96
|
+
res.status(response.status).json({ account, user, tokens });
|
|
97
97
|
} else {
|
|
98
98
|
const { tokens, urlToRedirect } = response.data;
|
|
99
99
|
setAuthCookies(res, tokens, account, user, this.options.appUrl);
|
|
@@ -105,18 +105,17 @@ class AuthMiddleware {
|
|
|
105
105
|
};
|
|
106
106
|
|
|
107
107
|
handleRegister = async (req, res) => {
|
|
108
|
-
const { name, email,
|
|
108
|
+
const { name, email, password } = req.body;
|
|
109
109
|
const { returnTokens } = req.query;
|
|
110
110
|
|
|
111
111
|
try {
|
|
112
112
|
const response = await this.proxyToAuthServer(
|
|
113
113
|
req,
|
|
114
|
-
|
|
114
|
+
`/api/v1/auth/register?returnTokens=${returnTokens}`,
|
|
115
115
|
'POST',
|
|
116
116
|
{
|
|
117
117
|
name,
|
|
118
118
|
email,
|
|
119
|
-
username,
|
|
120
119
|
password,
|
|
121
120
|
clientId: this.options.clientId,
|
|
122
121
|
redirectUri: this.options.redirectUri,
|
|
@@ -124,11 +123,11 @@ class AuthMiddleware {
|
|
|
124
123
|
}
|
|
125
124
|
);
|
|
126
125
|
|
|
127
|
-
const { account } = response.data;
|
|
126
|
+
const { account, tokens } = response.data;
|
|
128
127
|
const user = await checkIfUserExists(this.userSchema, account.accountId);
|
|
129
128
|
|
|
130
129
|
if (returnTokens === 'true') {
|
|
131
|
-
res.status(response.status).json(
|
|
130
|
+
res.status(response.status).json({ account, user, tokens });
|
|
132
131
|
} else {
|
|
133
132
|
const { urlToRedirect } = response.data;
|
|
134
133
|
res.status(response.status).json({ urlToRedirect });
|
|
@@ -139,7 +138,7 @@ class AuthMiddleware {
|
|
|
139
138
|
};
|
|
140
139
|
|
|
141
140
|
handleCallback = async (req, res) => {
|
|
142
|
-
const { code } = req.query;
|
|
141
|
+
const { code, returnTokens } = req.query;
|
|
143
142
|
if (!code) {
|
|
144
143
|
return res.status(400).send('No code received');
|
|
145
144
|
}
|
|
@@ -154,6 +153,10 @@ class AuthMiddleware {
|
|
|
154
153
|
);
|
|
155
154
|
|
|
156
155
|
const user = await checkIfUserExists(this.userSchema, account.accountId);
|
|
156
|
+
|
|
157
|
+
if (returnTokens === 'true') {
|
|
158
|
+
return res.status(200).json({ account, user, tokens });
|
|
159
|
+
}
|
|
157
160
|
setAuthCookies(res, tokens, account, user, redirectUrl);
|
|
158
161
|
|
|
159
162
|
res.redirect(formatRedirectUrl(redirectUrl));
|