You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Must be using `express-session` for session management
11
+
- Must be using a valid session store (e.g., `express-mysql-session` for MySQL)
12
+
7
13
## Usage
8
14
9
15
Include the `commtrackr` package in your Express.js application:
10
16
11
17
```javascript
12
18
constexpress=require('express');
13
-
constcommtrackr=require('commtrackr'); // Import the commtrackr package
19
+
20
+
constsession=require("express-session");
21
+
constMySQLStore=require('express-mysql-session')(session); // Use a MySQL session store
22
+
constsessionStore=newMySQLStore({
23
+
host:'',
24
+
port:3306,
25
+
user:'',
26
+
password:'',
27
+
database:''
28
+
});
29
+
app.use(session({
30
+
name:'',
31
+
key:'',
32
+
secret:'',
33
+
store: sessionStore,
34
+
resave:false,
35
+
saveUninitialized:false
36
+
}));
37
+
14
38
constapp=express();
39
+
40
+
constcommtrackr=require('commtrackr'); // Import the commtrackr package
15
41
app.use('/commtrackr', commtrackr.routes); // Mount routes to /commtrackr path
16
42
commtrackr.init({ // Initialize CommTracker with configurations
17
43
tenant: {
@@ -29,8 +55,69 @@ commtrackr.init({ // Initialize CommTracker with configurations
29
55
url:'', // URL to redirect to for authentication
30
56
},
31
57
},
58
+
vars: {
59
+
userId:'username', // req.session object variable for unique user identification
60
+
userName:'name', // req.session object variable for user name
61
+
role:'role', // req.session object variable for user role
62
+
commissions:'commissions', // req.session object variable for user commissions array
63
+
},
32
64
});
65
+
33
66
app.listen(3000, () => {
34
67
console.log('Server is running on http://localhost:3000');
35
68
});
36
69
```
70
+
71
+
## Session Variables Setup
72
+
73
+
These variables must be set in your `req.session` object to enable CommTrackr functionality:
74
+
75
+
### userId
76
+
77
+
`req.session.userId` must contain a unique identifier for the user, such as a username or user ID. This is used to track user-specific data. This must be present for CommTrackr to detect a logged-in user.
78
+
79
+
Type: `String`
80
+
81
+
Fallback: None
82
+
83
+
Example: `'username'`
84
+
85
+
### userName
86
+
87
+
`req.session.userName` should contain the name of the user. This is used for display purposes in the CommTrackr interface. Fallback to `userId` if not set.
88
+
89
+
Type: `String`
90
+
91
+
Fallback: `req.session.userId`
92
+
93
+
Example: `'John Doe'`
94
+
95
+
### role
96
+
97
+
`req.session.role` should contain the role of the user: 'admin', `dev`, or 'user'. This is used to control access to certain features and functionalities within CommTrackr.
98
+
99
+
Type: `String`
100
+
101
+
Fallback: `user`
102
+
103
+
Example: `'user'`, `'dev'`, `'admin'`
104
+
105
+
### commissions
106
+
107
+
`req.session.commissions` should be an array of commission objects associated with the user. Each commission object should have the following structure:
108
+
109
+
Type: `Array`
110
+
111
+
Example:
112
+
113
+
```javascript
114
+
[
115
+
{
116
+
id:'unique-commission-id', // Unique identifier for the commission
117
+
client:'Client Name', // Name of the client
118
+
amount:1000, // Commission amount
119
+
date:'2023-10-01', // Date of the commission
120
+
status:'pending'// Status of the commission (e.g., 'pending', 'paid')
0 commit comments