propro-utils 1.5.18 → 1.5.20

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "propro-utils",
3
- "version": "1.5.18",
3
+ "version": "1.5.20",
4
4
  "description": "Auth middleware for propro-auth",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -52,6 +52,7 @@ class AuthMiddleware {
52
52
  initializeRoutes() {
53
53
  this.router.post('/api/auth', this.handleAuth);
54
54
  this.router.post('/api/login', this.handleLogin);
55
+ this.router.post('/api/magiclink', this.handleMagicLink);
55
56
  this.router.post('/api/register', this.handleRegister);
56
57
  this.router.get('/api/callback', this.handleCallback);
57
58
  this.router.post('/api/refreshToken', this.handleRefreshToken);
@@ -99,6 +100,18 @@ class AuthMiddleware {
99
100
  }
100
101
  };
101
102
 
103
+ handleMagicLink = async (req, res) => {
104
+ try {
105
+ const response = await this.proxyToAuthServer(
106
+ req,
107
+ '/api/v1/auth/send-magic-link'
108
+ );
109
+ res.status(response.status).json(response.data);
110
+ } catch (error) {
111
+ this.handleProxyError(error, res);
112
+ }
113
+ };
114
+
102
115
  handleRegister = async (req, res) => {
103
116
  const { returnTokens } = req.query;
104
117
 
@@ -140,6 +153,10 @@ class AuthMiddleware {
140
153
 
141
154
  const user = await checkIfUserExists(this.userSchema, account.accountId);
142
155
 
156
+ if (!user) {
157
+ throw new Error('User not found');
158
+ }
159
+
143
160
  if (returnTokens === 'true') {
144
161
  return res.status(200).json({ account, user, tokens });
145
162
  }