Skip to content

Commit 9438d01

Browse files
removed unused functions from jwt.js - updated port on DE
1 parent bf68572 commit 9438d01

File tree

12 files changed

+1259
-90
lines changed

12 files changed

+1259
-90
lines changed

Data Client/database.js

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@ const db = new sqlite3Verbose.Database("./db/database.db");
1313

1414
// Create authorizations table
1515
db.serialize(() => {
16-
db.run(`
17-
CREATE TABLE IF NOT EXISTS authorizations (
18-
id TEXT PRIMARY KEY,
19-
email TEXT,
20-
firstName TEXT,
21-
lastName TEXT,
22-
accessToken TEXT
23-
)
24-
`);
25-
2616
// Table to associate site ID with access token from OAuth
2717
db.run(`
2818
CREATE TABLE IF NOT EXISTS siteAuthorizations (
@@ -41,39 +31,6 @@ db.serialize(() => {
4131
`);
4232
});
4333

44-
// Function to insert user into the database or return existing user
45-
function insertAuthorization(user) {
46-
// Check if the user already exists
47-
db.get(
48-
"SELECT * FROM authorizations WHERE id = ?",
49-
[user.id],
50-
(err, existingUser) => {
51-
if (err) {
52-
console.error("Error checking for existing user:", err);
53-
return;
54-
}
55-
56-
// If the user already exists, return the existing user
57-
if (existingUser) {
58-
console.log("User already exists:", existingUser);
59-
}
60-
61-
// If the user doesn't exist, insert the new user
62-
db.run(
63-
"INSERT INTO authorizations (id, email, firstName, lastName, accessToken) VALUES (?, ?, ?, ?, ?)",
64-
[user.id, user.email, user.firstName, user.lastName, user.accessToken],
65-
(err) => {
66-
if (err) {
67-
console.error("Error inserting user:", err);
68-
} else {
69-
console.log("User inserted successfully.");
70-
}
71-
}
72-
);
73-
}
74-
);
75-
}
76-
7734
// Insert a record after exchanging the OAuth code for an access token
7835
function insertSiteAuthorization(siteId, accessToken) {
7936
db.get(
@@ -187,31 +144,6 @@ function getAccessTokenFromUserId(userId, callback) {
187144
);
188145
}
189146

190-
// Function to retrieve and decrypt the access token for a user
191-
function getAccessToken(userId, callback) {
192-
// Retrieve the access token from the database
193-
db.get(
194-
"SELECT accessToken FROM authorizations WHERE id = ?",
195-
[userId],
196-
(err, row) => {
197-
if (err) {
198-
console.error("Error retrieving user:", err);
199-
return callback(err, null);
200-
}
201-
// Check if user exists and has an accessToken
202-
if (row && row.accessToken) {
203-
return callback(null, row.accessToken);
204-
} else {
205-
// No user or no access token available
206-
return callback(
207-
new Error("No access token found or user does not exist"),
208-
null
209-
);
210-
}
211-
}
212-
);
213-
}
214-
215147
function clearDatabase() {
216148
db.serialize(() => {
217149
// Clear data from authorizations table
@@ -243,15 +175,10 @@ function clearDatabase() {
243175
});
244176
}
245177

246-
// Example usage
247-
clearDatabase();
248-
249178
export default {
250179
db,
251-
insertAuthorization,
252180
insertSiteAuthorization,
253181
insertUserAuthorization,
254-
getAccessToken,
255182
getAccessTokenFromSiteId,
256183
getAccessTokenFromUserId,
257184
clearDatabase,

Data Client/db/database.db

28 KB
Binary file not shown.

Data Client/jwt.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
import jwt from "jsonwebtoken";
22
import db from "./database.js";
33

4-
const createSessionToken = (user) => {
5-
const sessionToken = jwt.sign({ user }, process.env.WEBFLOW_CLIENT_SECRET, {
6-
expiresIn: "24h",
7-
}); // Example expiration time of 1 hour}
8-
const decodedToken = jwt.decode(sessionToken);
9-
return {
10-
sessionToken,
11-
exp: decodedToken.exp,
12-
};
13-
};
14-
154
// Given a site ID, retrieve associated Access Token
165
const retrieveAccessToken = (req, res, next) => {
176
const idToken = req.body.idToken;
@@ -35,6 +24,17 @@ const retrieveAccessToken = (req, res, next) => {
3524
});
3625
};
3726

27+
const createSessionToken = (user) => {
28+
const sessionToken = jwt.sign({ user }, process.env.WEBFLOW_CLIENT_SECRET, {
29+
expiresIn: "24h",
30+
}); // Example expiration time of 1 hour}
31+
const decodedToken = jwt.decode(sessionToken);
32+
return {
33+
sessionToken,
34+
exp: decodedToken.exp,
35+
};
36+
};
37+
3838
// Middleware to authenticate and validate JWT, and fetch the access token given the user ID
3939
const authenticateSessionToken = (req, res, next) => {
4040
const authHeader = req.headers.authorization;

Designer Extension/bundle.zip

91.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)