propro-utils 1.5.57 → 1.5.59
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/middlewares/account_info.js +38 -10
- package/package.json +1 -1
- package/src/server/index.js +2 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require('dotenv').config();
|
|
2
2
|
const axios = require('axios');
|
|
3
|
+
const mongoose = require('mongoose');
|
|
3
4
|
const { getOrSetCache } = require('../utils/redis');
|
|
4
5
|
const { v4: uuidv4 } = require('uuid');
|
|
5
6
|
const ServiceManager = require('../utils/serviceManager');
|
|
@@ -99,26 +100,37 @@ async function createDefaultFolders(folderSchema, accountId) {
|
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
102
|
|
|
102
|
-
/**
|
|
103
|
-
* Checks if a user exists based on the given account ID.
|
|
104
|
-
* If the user does not exist, creates a new user with the given account ID.
|
|
105
|
-
* If the user exists but doesn't have global styles, creates them.
|
|
106
|
-
*
|
|
107
|
-
* @param {string} accountId - The account ID of the user to check/create.
|
|
108
|
-
* @returns {Promise<Object>} A promise that resolves to the user object.
|
|
109
|
-
* @throws {Error} If there's an issue with database operations.
|
|
110
|
-
*/
|
|
111
103
|
const checkIfUserExists = async accountId => {
|
|
112
104
|
try {
|
|
113
105
|
const userSchema = await ServiceManager.getService('UserSchema');
|
|
114
106
|
const userStyleSchema = await ServiceManager.getService('UserStyleSchema');
|
|
115
107
|
const folderSchema = await ServiceManager.getService('FolderSchema');
|
|
108
|
+
const Theme = mongoose.model('Theme');
|
|
116
109
|
|
|
117
110
|
let user = await userSchema
|
|
118
111
|
.findOne({ accountId })
|
|
119
112
|
.populate('userGlobalStyles');
|
|
120
113
|
|
|
121
114
|
if (user) {
|
|
115
|
+
if (!user.theme) {
|
|
116
|
+
let defaultTheme = await Theme.findOne({
|
|
117
|
+
name: 'Default Theme',
|
|
118
|
+
accountId,
|
|
119
|
+
});
|
|
120
|
+
if (!defaultTheme) {
|
|
121
|
+
defaultTheme = await Theme.create({
|
|
122
|
+
canvasBackground: '#000000',
|
|
123
|
+
defaultItemWidth: 200,
|
|
124
|
+
defaultColor: '#ffffff',
|
|
125
|
+
fontSize: '16px',
|
|
126
|
+
name: 'Default Theme',
|
|
127
|
+
id: uuidv4(),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
user.theme = defaultTheme._id;
|
|
131
|
+
await user.save();
|
|
132
|
+
}
|
|
133
|
+
|
|
122
134
|
if (!user.userGlobalStyles) {
|
|
123
135
|
user.userGlobalStyles = await createUserGlobalStyles(
|
|
124
136
|
userStyleSchema,
|
|
@@ -129,7 +141,7 @@ const checkIfUserExists = async accountId => {
|
|
|
129
141
|
user.userGlobalStyles.styleShortcuts = defaultUserGlobalStyleShortcuts;
|
|
130
142
|
await user.userGlobalStyles.save();
|
|
131
143
|
}
|
|
132
|
-
|
|
144
|
+
|
|
133
145
|
const userFolders = await folderSchema.find({ user_id: user.id });
|
|
134
146
|
const defaultFolderNames = defaultFolders.map(folder => folder.name);
|
|
135
147
|
const userFolderNames = userFolders.map(folder => folder.name);
|
|
@@ -152,6 +164,21 @@ const checkIfUserExists = async accountId => {
|
|
|
152
164
|
return user;
|
|
153
165
|
}
|
|
154
166
|
|
|
167
|
+
let defaultTheme = await Theme.findOne({
|
|
168
|
+
name: 'Default Theme',
|
|
169
|
+
accountId,
|
|
170
|
+
});
|
|
171
|
+
if (!defaultTheme) {
|
|
172
|
+
defaultTheme = await Theme.create({
|
|
173
|
+
canvasBackground: '#000000',
|
|
174
|
+
defaultItemWidth: 200,
|
|
175
|
+
defaultColor: '#ffffff',
|
|
176
|
+
fontSize: '16px',
|
|
177
|
+
name: 'Default Theme',
|
|
178
|
+
id: uuidv4(),
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
155
182
|
const userGlobalStyles = await createUserGlobalStyles(
|
|
156
183
|
userStyleSchema,
|
|
157
184
|
accountId
|
|
@@ -162,6 +189,7 @@ const checkIfUserExists = async accountId => {
|
|
|
162
189
|
id: uuidv4(),
|
|
163
190
|
verified: false,
|
|
164
191
|
userGlobalStyles: userGlobalStyles._id,
|
|
192
|
+
theme: defaultTheme._id,
|
|
165
193
|
});
|
|
166
194
|
|
|
167
195
|
const folders = await createDefaultFolders(folderSchema, user.id);
|
package/package.json
CHANGED
package/src/server/index.js
CHANGED
|
@@ -210,7 +210,8 @@ class AuthMiddleware {
|
|
|
210
210
|
const refreshToken =
|
|
211
211
|
req.cookies['x-refresh-token'] || req.headers['x-refresh-token'];
|
|
212
212
|
if (!refreshToken) {
|
|
213
|
-
|
|
213
|
+
clearAuthCookies(res);
|
|
214
|
+
return this.handleAuth(req, res);
|
|
214
215
|
}
|
|
215
216
|
|
|
216
217
|
try {
|