mirror of
https://github.com/HeyPuter/puter.git
synced 2026-05-04 08:30:39 +00:00
feat: add puter.auth.whoami()
This commit is contained in:
@@ -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);
|
||||
})
|
||||
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user