feat: add puter.auth.whoami()

This commit is contained in:
KernelDeimos
2024-11-05 15:49:51 -05:00
parent 755736edee
commit da0022abf0
2 changed files with 19 additions and 1 deletions
+10 -1
View File
@@ -24,7 +24,7 @@ const fs = require('../middleware/fs.js');
const _path = require('path');
const eggspress = require('../api/eggspress');
const { Context } = require('../util/context');
const { UserActorType } = require('../services/auth/Actor');
const { UserActorType, AppUnderUserActorType } = require('../services/auth/Actor');
// -----------------------------------------------------------------------//
// GET /whoami
@@ -82,6 +82,15 @@ const WHOAMI_GET = eggspress('/whoami', {
delete details.token;
}
if ( actor.type instanceof AppUnderUserActorType ) {
details.app_name = actor.type.app.name;
// IDEA: maybe we do this in the future
// details.app = {
// name: actor.type.app.name,
// };
}
res.send(details);
})
+9
View File
@@ -109,6 +109,15 @@ class Auth{
signOut = () =>{
puter.resetAuthToken();
}
async whoami () {
const resp = await fetch(this.APIOrigin + '/whoami', {
headers: {
Authorization: `Bearer ${this.authToken}`
}
});
return await resp.json();
}
}
export default Auth