@@ -13,16 +13,6 @@ const db = new sqlite3Verbose.Database("./db/database.db");
13
13
14
14
// Create authorizations table
15
15
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
-
26
16
// Table to associate site ID with access token from OAuth
27
17
db . run ( `
28
18
CREATE TABLE IF NOT EXISTS siteAuthorizations (
@@ -41,39 +31,6 @@ db.serialize(() => {
41
31
` ) ;
42
32
} ) ;
43
33
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
-
77
34
// Insert a record after exchanging the OAuth code for an access token
78
35
function insertSiteAuthorization ( siteId , accessToken ) {
79
36
db . get (
@@ -187,31 +144,6 @@ function getAccessTokenFromUserId(userId, callback) {
187
144
) ;
188
145
}
189
146
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
-
215
147
function clearDatabase ( ) {
216
148
db . serialize ( ( ) => {
217
149
// Clear data from authorizations table
@@ -243,15 +175,10 @@ function clearDatabase() {
243
175
} ) ;
244
176
}
245
177
246
- // Example usage
247
- clearDatabase ( ) ;
248
-
249
178
export default {
250
179
db,
251
- insertAuthorization,
252
180
insertSiteAuthorization,
253
181
insertUserAuthorization,
254
- getAccessToken,
255
182
getAccessTokenFromSiteId,
256
183
getAccessTokenFromUserId,
257
184
clearDatabase,
0 commit comments