Skip to content

Commit

Permalink
Restore login state from session
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Dec 5, 2024
1 parent dd2ae0d commit 7678270
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/HttpApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,49 @@ async function httpApi(uw, options) {
secure: uw.express.get('env') === 'production',
httpOnly: true,
},
store: new class extends session.Store {

Check failure on line 125 in src/HttpApi.js

View workflow job for this annotation

GitHub Actions / Code style

Missing '()' invoking a constructor

Check failure on line 125 in src/HttpApi.js

View workflow job for this annotation

GitHub Actions / Code style

Missing '()' invoking a constructor
/**
* @param {string} sid
* @param {(err?: Error, data?: session.SessionData | null) => void} callback
*/
get (sid, callback) {

Check failure on line 130 in src/HttpApi.js

View workflow job for this annotation

GitHub Actions / Code style

Unexpected space before function parentheses

Check failure on line 130 in src/HttpApi.js

View workflow job for this annotation

GitHub Actions / Code style

Unexpected space before function parentheses
uw.redis.get(`session:${sid}`).then((data) => {
callback(undefined, data == null ? null : JSON.parse(data));
}, (err) => {
callback(err);
})

Check failure on line 135 in src/HttpApi.js

View workflow job for this annotation

GitHub Actions / Code style

Missing semicolon

Check failure on line 135 in src/HttpApi.js

View workflow job for this annotation

GitHub Actions / Code style

Missing semicolon
}

/**
* @param {string} sid
* @param {session.SessionData} data
* @param {(err?: Error) => void} callback
*/
set(sid, data, callback) {
uw.redis.set(`session:${sid}`, JSON.stringify(data)).then(() => {
callback();
}, (err) => {
callback(err);
})

Check failure on line 148 in src/HttpApi.js

View workflow job for this annotation

GitHub Actions / Code style

Missing semicolon

Check failure on line 148 in src/HttpApi.js

View workflow job for this annotation

GitHub Actions / Code style

Missing semicolon
}

/**
* @param {string} sid
* @param {(err?: Error) => void} callback
*/
destroy(sid, callback) {
uw.redis.del(`session:${sid}`).then(() => {
callback();
}, (err) => {
callback(err);
})

Check failure on line 160 in src/HttpApi.js

View workflow job for this annotation

GitHub Actions / Code style

Missing semicolon

Check failure on line 160 in src/HttpApi.js

View workflow job for this annotation

GitHub Actions / Code style

Missing semicolon
}
},
}))
.use(uw.passport.initialize())
.use(addFullUrl())
.use(attachUwaveMeta(uw.httpApi, uw))
.use(uw.passport.authenticate('jwt'))
.use(uw.passport.session())
.use(rateLimit('api-http', { max: 500, duration: 60 * 1000 }));

uw.httpApi
Expand Down

0 comments on commit 7678270

Please sign in to comment.