1
1
import { forwardRef , Inject , Injectable } from '@nestjs/common' ;
2
- import { type ID , type Role , UnauthenticatedException } from '~/common' ;
2
+ import { type ID , type Role } from '~/common' ;
3
3
import { type IRequest } from '../http/types' ;
4
4
import { SessionHost } from './session/session.host' ;
5
5
import type { SessionInitiator } from './session/session.initiator' ;
@@ -44,9 +44,7 @@ export class Identity {
44
44
* Manually verify the current requestor is logged in.
45
45
*/
46
46
verifyLoggedIn ( session ?: Identity [ 'current' ] ) {
47
- if ( ( session ?? this . current ) . anonymous ) {
48
- throw new UnauthenticatedException ( 'User is not logged in' ) ;
49
- }
47
+ ( session ?? this . current ) . verifyLoggedIn ( ) ;
50
48
}
51
49
52
50
/**
@@ -56,7 +54,7 @@ export class Identity {
56
54
* Prefer using Auth Policies / {@link Privileges}`.for.can()`
57
55
*/
58
56
get isAdmin ( ) {
59
- return this . current . roles . includes ( 'global:Administrator' ) ;
57
+ return this . current . isAdmin ;
60
58
}
61
59
62
60
/**
@@ -68,9 +66,7 @@ export class Identity {
68
66
*/
69
67
get isImpersonatorAdmin ( ) {
70
68
const session = this . current ;
71
- return ( session . impersonator ?? session ) . roles . includes (
72
- 'global:Administrator' ,
73
- ) ;
69
+ return ( session . impersonator ?? session ) . isAdmin ;
74
70
}
75
71
76
72
/**
@@ -80,7 +76,7 @@ export class Identity {
80
76
* Prefer using Auth Policies / {@link Privileges}`.for.can()`
81
77
*/
82
78
isSelf ( id : ID < 'User' > ) {
83
- return id === this . current . userId ;
79
+ return this . current . isSelf ( id ) ;
84
80
}
85
81
86
82
async asUser < R > ( user : ID < 'User' > , fn : ( ) => Promise < R > ) : Promise < R > {
0 commit comments