Merge pull request #267 from HeyPuter/eric/session-fixes

session management fixes
This commit is contained in:
Eric Dubé 2024-04-12 00:29:26 -04:00 committed by GitHub
commit eb96dd952b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 19 additions and 2 deletions

View File

@ -63,8 +63,10 @@ const auth2 = async (req, res, next) => {
if(!token) {
APIError.create('token_missing').write(res);
return;
} else if (typeof token !== 'string') {
APIError.create('token_auth_failed').write(res);
return;
} else {
token = token.replace('Bearer ', '')
}

View File

@ -71,6 +71,11 @@ module.exports = eggspress(['/signup'], {
const { user, token } = await svc_auth.check_session(
req.cookies[config.cookie_name]
);
res.cookie(config.cookie_name, token, {
sameSite: 'none',
secure: true,
httpOnly: true,
});
// const decoded = await jwt.verify(token, config.jwt_secret);
// const user = await get_user({ uuid: decoded.uuid });
if ( user ) {

View File

@ -240,7 +240,10 @@ class AuthService extends BaseService {
[uuid],
);
session.meta = JSON.parse(session.meta ?? {});
session.meta = this.db.case({
mysql: () => session.meta,
otherwise: () => JSON.parse(session.meta ?? "{}")
})();
return session;
}
@ -375,10 +378,13 @@ class AuthService extends BaseService {
);
sessions.forEach(session => {
session.meta = this.db.case({
mysql: () => session.meta,
otherwise: () => JSON.parse(session.meta ?? "{}")
})();
if ( session.uuid === actor.type.session ) {
session.current = true;
}
session.meta = JSON.parse(session.meta ?? {});
});
return sessions;

View File

@ -87,6 +87,7 @@ const UIWindowManageSessions = async function UIWindowManageSessions () {
const resp = await fetch(`${api_origin}/auth/revoke-session`, {
method: 'POST',
headers: {
Authorization: `Bearer ${puter.authToken}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
@ -115,6 +116,9 @@ const UIWindowManageSessions = async function UIWindowManageSessions () {
const reload_sessions = async () => {
const resp = await fetch(`${api_origin}/auth/list-sessions`, {
headers: {
Authorization: `Bearer ${puter.authToken}`,
},
method: 'GET',
});