propro-utils 1.3.8

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.
@@ -0,0 +1,110 @@
1
+ # Notification System
2
+
3
+ This notification system provides a flexible and robust way to send notifications through various channels like SMS and email. It employs the strategy pattern to allow for easy extension and customization of notification methods.
4
+
5
+ ## System Overview
6
+
7
+ The system is built around a base `NotificationStrategy` class, which different notification strategies extend. Currently, the system supports SMS notifications via Twilio and Mailjet, and email notifications using the Mailgun service.
8
+
9
+ ### Strategies
10
+
11
+ - `TwilioSMSNotificationStrategy`: Sends SMS using Twilio.
12
+ - `MailjetSMSNotificationStrategy`: Sends SMS using Mailjet.
13
+ - `EmailNotificationStrategy`: Sends emails using the Mailgun service.
14
+
15
+ ### Notification Service
16
+
17
+ - `NotificationService`: Handles the sending of notifications. It can be configured with any of the available strategies.
18
+
19
+ ## Setup and Configuration
20
+
21
+ Before using the notification system, ensure that all the necessary dependencies are installed and environment variables are set.
22
+
23
+ ### Dependencies
24
+
25
+ - `axios`
26
+ - `twilio`
27
+ - `mailgun.js`
28
+ - `form-data`
29
+ - `@react-email/render`
30
+
31
+ ### Environment Variables
32
+
33
+ Set the following environment variables in your application:
34
+
35
+ - `TWILIO_ACCOUNT_SID`
36
+ - `TWILIO_AUTH_TOKEN`
37
+ - `TWILIO_PHONE_NUMBER`
38
+ - `MAILJET_MJ_TOKEN`
39
+ - `MAILGUN_API_KEY`
40
+ - `EMAIL_FROM`
41
+ - `EMAIL_DOMAIN`
42
+
43
+ ## Usage
44
+
45
+ Here's how you can use the different strategies in your application:
46
+
47
+ ### Sending an SMS with Twilio
48
+
49
+ ```javascript
50
+ const {
51
+ NotificationService,
52
+ TwilioSMSNotificationStrategy,
53
+ } = require("propro-auth-middleware/notify");
54
+
55
+ const twilioStrategy = new TwilioSMSNotificationStrategy();
56
+ const notificationService = new NotificationService(twilioStrategy);
57
+
58
+ notificationService
59
+ .sendNotification("+1234567890", "Your SMS message here")
60
+ .then((response) => console.log("SMS sent with SID:", response))
61
+ .catch((error) => console.error("Error sending SMS:", error));
62
+ ```
63
+
64
+ ### Sending an SMS with Mailjet
65
+
66
+ ```javascript
67
+ const {
68
+ NotificationService,
69
+ MailjetSMSNotificationStrategy,
70
+ } = require("propro-auth-middleware/notify");
71
+
72
+ const mailjetStrategy = new MailjetSMSNotificationStrategy();
73
+ const notificationService = new NotificationService(mailjetStrategy);
74
+
75
+ notificationService
76
+ .sendNotification("+1234567890", "Your SMS message here")
77
+ .then((response) => console.log("SMS sent with SID:", response))
78
+ .catch((error) => console.error("Error sending SMS:", error));
79
+ ```
80
+
81
+ ### Sending an email with Mailgun
82
+
83
+ ```javascript
84
+
85
+ const {
86
+ NotificationService,
87
+ EmailNotificationStrategy,
88
+ } = require('propro-auth-middleware/notify');
89
+
90
+ const emailStrategy = new EmailNotificationStrategy();
91
+ const notificationService = new NotificationService(emailStrategy);
92
+
93
+ const emailDetails = {
94
+ template: "template-name",
95
+ to: "dozie@hubhub.app",
96
+ additionalData: {
97
+ name: "Dozie",
98
+ message: "Your email message here"
99
+ }
100
+ }:
101
+
102
+ notificationService
103
+ .sendNotification(emailDetails)
104
+ .then((response) => console.log("Email sent with ID:", response))
105
+ .catch((error) => console.error("Error sending email:", error));
106
+ ```
107
+
108
+ ## Extending the System
109
+
110
+ To add a new notification strategy, simply extend the `NotificationStrategy` class and implement the `sendNotification` method. Then, add the new strategy to the `NotificationService` class.
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Represents a notification strategy.
3
+ * @class
4
+ */
5
+ class NotificationStrategy {
6
+ async sendNotification(to, message) {
7
+ throw new Error("sendNotification method should be implemented");
8
+ }
9
+ }
10
+
11
+ module.exports = {
12
+ NotificationStrategy,
13
+ };
@@ -0,0 +1,57 @@
1
+ require("dotenv").config();
2
+ const React = require("react");
3
+ const ReactDOMServer = require("react-dom/server");
4
+ const NotifLocal = require("./NotifLocal");
5
+ const nodemailer = require("nodemailer");
6
+ const mailgun = require("nodemailer-mailgun-transport");
7
+ const { templateData } = require("./template.data");
8
+ const { NotificationStrategy } = require("./baseStrategy");
9
+
10
+ const mailgunTransport = nodemailer.createTransport(
11
+ mailgun({
12
+ host: process.env.SMTP_HOST,
13
+ auth: {
14
+ api_key: process.env.MAILGUN_API_KEY,
15
+ domain: process.env.EMAIL_DOMAIN,
16
+ },
17
+ })
18
+ );
19
+
20
+ /**
21
+ * Represents a strategy for sending email notifications.
22
+ */
23
+ class EmailNotificationStrategy extends NotificationStrategy {
24
+ async sendNotification(to, templateName, templateArgs) {
25
+ const templates = templateData(templateArgs || {});
26
+ const selectedTemplate = templates[templateName];
27
+
28
+ if (!selectedTemplate) {
29
+ throw new Error(`Template '${templateName}' not found`);
30
+ }
31
+
32
+ console.log("selectedTemplate", selectedTemplate);
33
+ console.log("templateData", templateData);
34
+ // const emailHTML = ReactDOMServer.renderToString(
35
+ // React.createElement(NotifLocal, selectedTemplate)
36
+ // );
37
+
38
+ const emailHTML = `<h1>${selectedTemplate.body}</h1>`;
39
+
40
+ const message = {
41
+ from: process.env.EMAIL_FROM,
42
+ to,
43
+ subject: selectedTemplate.subject || "New Notification",
44
+ html: emailHTML,
45
+ };
46
+
47
+ try {
48
+ console.log("Email Message Object:", message);
49
+ const info = await mailgunTransport.sendMail(message);
50
+ console.log("Message sent: %s", info.messageId);
51
+ } catch (error) {
52
+ console.error("Error sending email", error);
53
+ }
54
+ }
55
+ }
56
+
57
+ module.exports = { EmailNotificationStrategy };
@@ -0,0 +1,11 @@
1
+ const { EmailNotificationStrategy } = require("./emailStrategy");
2
+ const { MailjetSMSNotificationStrategy } = require("./mailjetStrategy");
3
+ const { TwilioSMSNotificationStrategy } = require("./twilloStrategy");
4
+ const { NotificationService } = require("./NotificationService");
5
+
6
+ module.exports = {
7
+ EmailNotificationStrategy,
8
+ MailjetSMSNotificationStrategy,
9
+ TwilioSMSNotificationStrategy,
10
+ NotificationService,
11
+ };
@@ -0,0 +1,27 @@
1
+ const axios = require("axios");
2
+ const { NotificationStrategy } = require("./baseStrategy");
3
+
4
+ /**
5
+ * Mailjet SMS Notification Strategy.
6
+ * @class
7
+ * @extends NotificationStrategy
8
+ */
9
+ class MailjetSMSNotificationStrategy extends NotificationStrategy {
10
+ async sendNotification(to, message) {
11
+ const response = await axios.post(
12
+ "https://api.mailjet.com/v4/sms-send",
13
+ { Text: message, To: to, From: "ProPro" },
14
+ {
15
+ headers: {
16
+ Authorization: `Bearer ${config.mailjet.MJ_TOKEN}`,
17
+ "Content-Type": "application/json",
18
+ },
19
+ }
20
+ );
21
+ return response.data.MessageId;
22
+ }
23
+ }
24
+
25
+ module.exports = {
26
+ MailjetSMSNotificationStrategy,
27
+ };
@@ -0,0 +1,292 @@
1
+ const templateData = ({ ...args }) => ({
2
+ "new-account": {
3
+ subject: "Welcome to ProPro",
4
+ body: "Thank you for signing up to ProPro. Please click the link below to verify your email address.",
5
+ button: {
6
+ label: "Verify Your Email",
7
+ url: "{{domain}}?token={{content.verification_token}}",
8
+ },
9
+ },
10
+ "duplicate-user": {
11
+ subject: "Important! Your ProPro Account",
12
+ body: "We noticed you already have a registered account with ProPro. To prevent confusion, your original password remains unchanged.",
13
+ button: {
14
+ label: "Sign In",
15
+ url: "{{domain}}/signin",
16
+ },
17
+ },
18
+ new_plan: {
19
+ subject: "Your ProPro Plan",
20
+ body: "Thank you for choosing the {{content.plan}} plan. Your card has been successfully charged {{content.price}}.",
21
+ button: {
22
+ label: "Your Dashboard",
23
+ url: "{{domain}}/dashboard",
24
+ },
25
+ },
26
+ "new-user": {
27
+ subject: "Welcome to ProPro",
28
+ body: "Thank you for signing up to ProPro. Please click the link below to verify your email address.",
29
+ button: {
30
+ label: "Verify Your Email",
31
+ url: "{{domain}}?token={{content.verification_token}}",
32
+ },
33
+ },
34
+ "plan-updated": {
35
+ subject: "Your Billing Plan Updated",
36
+ body: "Confirmation: Your billing plan has been updated to the {{content.plan}} plan.",
37
+ button: {
38
+ label: "Manage Your Plan",
39
+ url: "{{domain}}/account/billing",
40
+ },
41
+ },
42
+ "card-updated": {
43
+ subject: "Credit Card Information Updated",
44
+ body: "Confirmation: Your credit card information has been updated. Contact us immediately if you did not authorize this change.",
45
+ button: {
46
+ label: "Contact Support",
47
+ url: "mailto:support@yourdomain.com",
48
+ },
49
+ },
50
+ "account-closed": {
51
+ subject: "Account Closure Confirmation",
52
+ body: "Your account has been closed and all associated data has been removed from our servers. You're welcome to rejoin ProPro anytime.",
53
+ button: {
54
+ label: "Sign Up",
55
+ url: "{{domain}}/signup",
56
+ },
57
+ },
58
+ "invite-accepted": {
59
+ subject: "Team Invitation Accepted",
60
+ body: "Great news! {{content.friend}} has accepted your invitation to join your ProPro team.",
61
+ button: {
62
+ label: "Invite More Friends",
63
+ url: "{{domain}}/account/users",
64
+ },
65
+ },
66
+ "password-updated": {
67
+ subject: "Password Change Confirmation",
68
+ body: "Your ProPro password has been changed. If you did not initiate this change, please contact our support team immediately.",
69
+ button: {
70
+ label: "Contact Support",
71
+ url: "mailto:support@yourdomain.com",
72
+ },
73
+ },
74
+ "password-reset": {
75
+ subject: "Password Reset Request",
76
+ title: "Forgot Your ProPro Password?",
77
+ body: "To reset your password, click the link below.",
78
+ button: {
79
+ label: "Reset Password",
80
+ url: "{{domain}}?token={{content.token}}",
81
+ },
82
+ },
83
+ invite: {
84
+ subject: "Team Invitation from a Friend",
85
+ body: "You've been invited by {{content.friend}} to join their ProPro team. Sign up now to collaborate.",
86
+ button: {
87
+ label: "Sign Up Now",
88
+ url: "{{domain}}?id={{content.id}}&email={{content.email}}",
89
+ },
90
+ },
91
+ contact: {
92
+ subject: "New Contact Form Submission",
93
+ body: "You've received a new message from {{content.name}}: <br><br> {{content.message}}",
94
+ button: {
95
+ label: "Respond Now",
96
+ url: "mailto:{{content.email}}",
97
+ },
98
+ },
99
+ feedback: {
100
+ subject: "New App Feedback Received",
101
+ body: "New feedback for your ProPro app: <br><br> Rating: {{content.rating}} <br><br>{{content.comment}}",
102
+ button: {
103
+ label: "View Now",
104
+ url: "{{content.url}}",
105
+ },
106
+ },
107
+ magic_signin: {
108
+ subject: "Your ProPro Magic Sign-In Link",
109
+ body: "You requested a magic sign-in link for ProPro. Click below to sign in without a password.",
110
+ button: {
111
+ label: "Sign In",
112
+ url: "{{domain}}?token={{content.token}}",
113
+ },
114
+ },
115
+ new_signin: {
116
+ subject: "New Sign-In Alert for ProPro",
117
+ body: "A new sign-in to your ProPro account was detected: \n\n{{content.browser}} on {{content.device}}\n\nIP: {{content.ip}}\n\nTime: {{content.time}}\n\nIf this was you, no action is needed. If not, please secure your account.",
118
+ button: {
119
+ label: "Secure My Account",
120
+ url: "{{domain}}/account/security",
121
+ },
122
+ },
123
+ blocked_signin: {
124
+ subject: "Blocked Suspicious Sign-In Attempt",
125
+ body: "A suspicious sign-in attempt to your ProPro account was blocked. If this was you, use the link below to sign in securely.",
126
+ button: {
127
+ label: "Sign In Securely",
128
+ url: "{{domain}}?token={{content.token}}",
129
+ },
130
+ },
131
+ help: {
132
+ subject: "New Support Request Received",
133
+ body: "A new support request has been submitted by {{content.name}}: <br><br> {{content.message}}",
134
+ button: {
135
+ label: "Respond Now",
136
+ url: "mailto:{{content.email}}",
137
+ },
138
+ },
139
+ "new-log": {
140
+ subject: "New Log Recorded in ProPro",
141
+ body: "A new log has been recorded in your ProPro application. Check Mission Control for details.",
142
+ button: {
143
+ label: "View Log",
144
+ url: "{{domain}}/missioncontrol/logs/{{content.id}}",
145
+ },
146
+ },
147
+ email_verification: {
148
+ subject: "Verify Your ProPro Email",
149
+ body: "Thanks for signing up to ProPro. Click the link below to verify your email address.",
150
+ button: {
151
+ label: "Verify Your Email",
152
+ url: "{{domain}}?token={{content.verification_token}}",
153
+ },
154
+ },
155
+ email_verification_complete: {
156
+ subject: "Email Verified - Welcome to ProPro",
157
+ body: "Your email address has been verified. Your ProPro account is now active.",
158
+ button: {
159
+ label: "Open Dashboard",
160
+ url: "{{domain}}/dashboard",
161
+ },
162
+ },
163
+ "new-email": {
164
+ subject: "Email Address Change Confirmation",
165
+ body: "You have changed your email address for your ProPro account. If you did not authorize this change, please contact us immediately.",
166
+ button: {
167
+ label: "Contact Support",
168
+ url: "mailto:support@yourdomain.com",
169
+ },
170
+ },
171
+ otp_request: {
172
+ subject: "Your ProPro One-Time Password",
173
+ body: "Your ProPro one-time password (OTP) is: {{content.otp}}",
174
+ additionalInfo: "This password will expire in 10 minutes.",
175
+ },
176
+ subscription_expiry: {
177
+ subject: "Your ProPro Subscription is Expiring",
178
+ body: "Your ProPro subscription will expire in {{content.days}} days. Renew now to continue enjoying our services.",
179
+ button: {
180
+ label: "Renew Subscription",
181
+ url: "{{domain}}/account/billing",
182
+ },
183
+ },
184
+ payment_failure: {
185
+ subject: "Your ProPro Payment Failed",
186
+ body: "We were unable to process your payment. Please update your billing information to avoid interruption of your ProPro services.",
187
+ button: {
188
+ label: "Update Billing Information",
189
+ url: "{{domain}}/account/billing",
190
+ },
191
+ },
192
+ account_recovery: {
193
+ subject: "ProPro Account Recovery",
194
+ body: "To recover your ProPro account, please click the link below.",
195
+ button: {
196
+ label: "Recover Account",
197
+ url: "{{domain}}?token={{content.token}}",
198
+ },
199
+ },
200
+ account_verified: {
201
+ subject: "Your ProPro Account is Verified",
202
+ body: "Your ProPro account is now verified. You can now use all the features available.",
203
+ button: {
204
+ label: "Get Started",
205
+ url: "{{domain}}/dashboard",
206
+ },
207
+ },
208
+ account_verification_failed: {
209
+ subject: "ProPro Account Verification Failed",
210
+ body: "Your attempt to verify your ProPro account failed. Please try again or contact support if you continue to have issues.",
211
+ button: {
212
+ label: "Contact Support",
213
+ url: "mailto:support@yourdomain.com",
214
+ },
215
+ },
216
+ report_ready: {
217
+ subject: "Your ProPro Report is Ready",
218
+ body: "Your requested report from ProPro is now ready for download.",
219
+ button: {
220
+ label: "Download Report",
221
+ url: "{{domain}}/report/{{content.id}}",
222
+ },
223
+ },
224
+ welcome_message: {
225
+ subject: "Welcome to ProPro!",
226
+ body: "We're excited to have you on board. Discover the possibilities and features available with ProPro.",
227
+ button: {
228
+ label: "Get Started",
229
+ url: "{{domain}}/dashboard",
230
+ },
231
+ },
232
+ congratulations: {
233
+ subject: "Congratulations from ProPro",
234
+ body: "Congratulations on reaching a new milestone with ProPro!",
235
+ button: {
236
+ label: "Celebrate Now",
237
+ url: "{{domain}}/rewards",
238
+ },
239
+ },
240
+ newsletter: {
241
+ subject: "ProPro Newsletter - {{content.month}}",
242
+ body: "Catch up on the latest news and updates from ProPro in our monthly newsletter.",
243
+ button: {
244
+ label: "Read Now",
245
+ url: "{{domain}}/newsletter/{{content.id}}",
246
+ },
247
+ },
248
+ security_alert: {
249
+ subject: "Security Alert: New Device Signed in to ProPro",
250
+ body: "A new device has just signed into your ProPro account. If this was you, you can safely ignore this email. If it wasn't you, please secure your account.",
251
+ button: {
252
+ label: "Secure My Account",
253
+ url: "{{domain}}/account/security",
254
+ },
255
+ },
256
+ promotion: {
257
+ subject: "Special Promotion Just for You from ProPro",
258
+ body: "We have a special promotion just for you. Unlock your exclusive deal from ProPro now.",
259
+ button: {
260
+ label: "Unlock Now",
261
+ url: "{{domain}}/promotions",
262
+ },
263
+ },
264
+ thank_you: {
265
+ subject: "Thank You for Choosing ProPro",
266
+ body: "Thank you for being a valued member of the ProPro community. We're glad to have you with us.",
267
+ button: {
268
+ label: "Explore More",
269
+ url: "{{domain}}/dashboard",
270
+ },
271
+ },
272
+ goodbye: {
273
+ subject: "Goodbye from ProPro",
274
+ body: "We're sad to see you go. If you ever decide to come back, ProPro will be here waiting for you.",
275
+ button: {
276
+ label: "Come Back",
277
+ url: "{{domain}}/signup",
278
+ },
279
+ },
280
+ confirmation: {
281
+ subject: "Action Required: Confirm Your Action",
282
+ body: "Please confirm your action by clicking the button below.",
283
+ button: {
284
+ label: "Confirm",
285
+ url: "{{domain}}?token={{content.token}}",
286
+ },
287
+ },
288
+ });
289
+
290
+ module.exports = {
291
+ templateData,
292
+ };
@@ -0,0 +1,15 @@
1
+ const { EmailNotificationStrategy } = require("./emailStrategy");
2
+ const { NotificationService } = require("./notificationService");
3
+
4
+ const notificationService = new NotificationService(
5
+ new EmailNotificationStrategy()
6
+ );
7
+
8
+ notificationService
9
+ .sendNotification("chidosiky2015@gmail.com", "new-account")
10
+ .then(() => {
11
+ console.log("Email sent");
12
+ })
13
+ .catch((error) => {
14
+ console.log("Error sending email", error);
15
+ });
@@ -0,0 +1,30 @@
1
+ const twilio = require("twilio");
2
+ const { NotificationStrategy } = require("./baseStrategy");
3
+
4
+ /**
5
+ * Twilio SMS Notification Strategy class.
6
+ * @class
7
+ * @extends NotificationStrategy
8
+ */
9
+ class TwilioSMSNotificationStrategy extends NotificationStrategy {
10
+ constructor() {
11
+ super();
12
+ this.twilioClient = twilio(
13
+ process.env.TWILIO_ACCOUNT_SID,
14
+ process.env.TWILIO_AUTH_TOKEN
15
+ );
16
+ }
17
+
18
+ async sendNotification(to, message) {
19
+ const response = await this.twilioClient.messages.create({
20
+ to,
21
+ from: process.env.TWILIO_PHONE_NUMBER,
22
+ body: message,
23
+ });
24
+ return response.sid;
25
+ }
26
+ }
27
+
28
+ module.exports = {
29
+ TwilioSMSNotificationStrategy,
30
+ };
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "propro-utils",
3
+ "version": "1.3.8",
4
+ "description": "Auth middleware for propro-auth",
5
+ "main": "src/index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "email": "email dev ",
9
+ "build": "babel notify --out-dir dist"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/propro-productions/propro-auth-middleware.git"
14
+ },
15
+ "keywords": [
16
+ "auth",
17
+ "middleware",
18
+ "propro-auth"
19
+ ],
20
+ "author": "ProPro",
21
+ "license": "ISC",
22
+ "bugs": {
23
+ "url": "https://github.com/propro-productions/propro-auth-middleware/issues"
24
+ },
25
+ "presets": [
26
+ "@babel/preset-env",
27
+ "@babel/preset-react"
28
+ ],
29
+ "babel": {
30
+ "presets": [
31
+ "@babel/preset-env",
32
+ "@babel/preset-react"
33
+ ]
34
+ },
35
+ "devDependencies": {
36
+ "@babel/cli": "^7.23.4",
37
+ "@babel/core": "^7.23.5",
38
+ "@babel/preset-env": "^7.23.5",
39
+ "@babel/preset-react": "^7.23.3"
40
+ },
41
+ "homepage": "https://github.com/propro-productions/propro-auth-middleware#readme",
42
+ "dependencies": {
43
+ "@react-email/button": "0.0.9",
44
+ "@react-email/column": "^0.0.8",
45
+ "@react-email/components": "^0.0.11",
46
+ "@react-email/container": "0.0.8",
47
+ "@react-email/font": "^0.0.4",
48
+ "@react-email/head": "^0.0.6",
49
+ "@react-email/heading": "^0.0.9",
50
+ "@react-email/hr": "^0.0.6",
51
+ "@react-email/html": "0.0.4",
52
+ "@react-email/img": "0.0.5",
53
+ "@react-email/link": "^0.0.6",
54
+ "@react-email/markdown": "^0.0.7",
55
+ "@react-email/preview": "^0.0.7",
56
+ "@react-email/render": "0.0.7",
57
+ "@react-email/row": "^0.0.6",
58
+ "@react-email/section": "0.0.9",
59
+ "@react-email/tailwind": "^0.0.12",
60
+ "@react-email/text": "0.0.5",
61
+ "axios": "^1.6.1",
62
+ "dotenv": "^16.3.1",
63
+ "express-rate-limit": "^7.1.4",
64
+ "nodemailer": "^6.9.7",
65
+ "nodemailer-mailgun-transport": "^2.1.5",
66
+ "querystring": "^0.2.1",
67
+ "react-email": "^1.9.5"
68
+ }
69
+ }
@@ -0,0 +1,5 @@
1
+ CLIENT_ID=07929acf-f4ef-458f-889f-db49f37ba54c
2
+ CLIENT_SECRET=$2a$10$FK5KnYQXfXHAIO2d8U4QgO9q5wl/hdiNthIgK91.HbqebSgsQb2Eq
3
+ REDIRECT_URI=localhost:8182/api/v1/auth/callback
4
+ AUTH_URL=localhost:8182/api/v1/auth
5
+ CLIENT_URL=localhost:3000
@@ -0,0 +1,24 @@
1
+ import axios from 'axios';
2
+
3
+ const setupClientMiddleware = () => {
4
+ axios.interceptors.request.use(function (config) {
5
+ const token = localStorage.getItem('token');
6
+ if (token) {
7
+ config.headers.Authorization = `Bearer ${token}`;
8
+ }
9
+ return config;
10
+ }, function (error) {
11
+ return Promise.reject(error);
12
+ });
13
+
14
+ axios.interceptors.response.use(function (response) {
15
+ return response;
16
+ }, function (error) {
17
+ if (error.response.status === 401) {
18
+ localStorage.removeItem('token');
19
+ }
20
+ return Promise.reject(error);
21
+ });
22
+ };
23
+
24
+ export default setupClientMiddleware;