Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
portal-apps-manage
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
angular
portal-apps-manage
Commits
61ef530f
Commit
61ef530f
authored
Oct 14, 2025
by
sawit
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
access token
parent
e9de2e4f
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
104 additions
and
16 deletions
+104
-16
home.component.ts
src/app/portal-manage/home/home.component.ts
+14
-5
header.component.ts
src/app/shared/components/header/header.component.ts
+10
-2
auth.service.ts
src/app/shared/services/auth.service.ts
+4
-1
token.service.ts
src/app/shared/services/token.service.ts
+76
-8
No files found.
src/app/portal-manage/home/home.component.ts
View file @
61ef530f
...
...
@@ -280,7 +280,7 @@ export class HomeComponent implements OnInit {
isVisible
:
true
,
category
:
'applications'
,
permissions
:
{
view
:
true
,
create
:
true
,
edit
:
true
,
delete
:
true
,
export
:
true
,
import
:
true
},
appUrl
:
environment
.
u
rl
appUrl
:
environment
.
baseU
rl
},
{
id
:
'MYSKILL-X'
,
...
...
@@ -378,11 +378,20 @@ export class HomeComponent implements OnInit {
confirmNavigation
()
{
if
(
this
.
selectedApp
)
{
window
.
sessionStorage
.
setItem
(
'environment'
,
this
.
selectedEnvironment
);
this
.
tokenService
.
saveAppToken
(
this
.
selectedApp
.
name
);
this
.
router
.
navigate
([
this
.
selectedApp
.
path
]);
window
.
sessionStorage
.
setItem
(
"module"
,
this
.
selectedApp
.
name
);
const
appToNavigate
=
this
.
selectedApp
;
this
.
tokenService
.
saveAppToken
(
appToNavigate
.
name
).
subscribe
({
next
:
()
=>
{
this
.
router
.
navigate
([
appToNavigate
.
path
]);
this
.
cancelNavigation
();
// Close modal on success
},
error
:
(
err
)
=>
{
console
.
error
(
'Failed to save token and navigate'
,
err
);
this
.
cancelNavigation
();
// Close modal on error
}
});
}
else
{
this
.
cancelNavigation
();
// Fallback to close modal
}
this
.
cancelNavigation
();
// Close modal and reset state
}
cancelNavigation
()
{
...
...
src/app/shared/components/header/header.component.ts
View file @
61ef530f
...
...
@@ -256,8 +256,16 @@ export class HeaderComponent {
}
checkAppToken
(
appmodule
:
string
){
this
.
tokenService
.
saveAppToken
(
appmodule
)
this
.
router
.
navigate
([
'/portal-manage/'
+
appmodule
])
this
.
tokenService
.
saveAppToken
(
appmodule
).
subscribe
({
next
:
()
=>
{
this
.
router
.
navigate
([
'/portal-manage/'
+
appmodule
]);
},
error
:
(
err
)
=>
{
console
.
error
(
`Failed to save token for
${
appmodule
}
and navigate`
,
err
);
// Fallback navigation even on error
this
.
router
.
navigate
([
'/portal-manage/'
+
appmodule
]);
}
});
}
routerApp
(
appmodule
:
string
){
...
...
src/app/shared/services/auth.service.ts
View file @
61ef530f
...
...
@@ -4,6 +4,7 @@ import { HttpClient } from '@angular/common/http';
import
{
LoginModel
,
ProfileModel
,
UserModel
}
from
'../user-auth.model'
;
import
{
environment
}
from
'../../../environments/environment'
;
import
{
Observable
,
tap
}
from
'rxjs'
;
import
{
TokenService
}
from
'./token.service'
;
@
Injectable
({
providedIn
:
'root'
,
})
...
...
@@ -13,6 +14,7 @@ export class AuthService {
public
generatedTokenData
:
any
;
constructor
(
private
http
:
HttpClient
,
private
tokenService
:
TokenService
,
)
{
}
...
...
@@ -46,12 +48,13 @@ export class AuthService {
return
this
.
http
.
get
<
any
>
(
environment
.
url
+
"/auth/generate-token"
,).
pipe
(
tap
(
response
=>
{
this
.
generatedTokenData
=
response
;
this
.
tokenService
.
saveModulesData
(
response
);
}
))
}
postPortalRefreshToken
(
appUrl
:
string
){
return
this
.
http
.
post
<
any
>
(
appUrl
+
"/refresh-token"
,
{
return
this
.
http
.
post
<
any
>
(
appUrl
+
"/
auth/portal/
refresh-token"
,
{
"refreshToken"
:
this
.
generatedTokenData
.
refreshToken
});
}
...
...
src/app/shared/services/token.service.ts
View file @
61ef530f
import
{
Injectable
}
from
"@angular/core"
;
import
{
Router
}
from
"@angular/router"
;
import
{
HttpClient
}
from
"@angular/common/http"
;
import
{
Observable
,
of
}
from
"rxjs"
;
import
{
tap
}
from
"rxjs/operators"
;
import
{
jwtDecode
}
from
"jwt-decode"
;
import
{
ProfileModel
,
UserModel
}
from
"../user-auth.model"
;
...
...
@@ -29,7 +32,7 @@ export class TokenService {
"ZEESERVER"
:
"eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBdXRoIiwidWlkIjoiOGFhNDUzMzAtMzE0Yy0xMWU3LWJhZjMtMmQ3ZDA5ODc3NzQ0Iiwicm9sZXMiOlsiYWRtaW4iXSwiaXNzIjoiQ29tcHV0ZXIgU2NpZW5jZSBDb3Jwb3JhdGlvbiBMaW1pdGVkIiwidXNlcm5hbWUiOiJhZG1pbiJ9.TzU5PKZ4jf8YeCEXA03IxLVRVmCh3AC2oTgT_KvBt6g"
,
"MYFACE"
:
""
,
"MYLEARN"
:
"eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBdXRoIiwidWlkIjoiOGFhNDUzMzAtMzE0Yy0xMWU3LWJhZjMtMmQ3ZDA5ODc3NzQ0Iiwicm9sZXMiOlsiYWRtaW4iXSwiaXNzIjoiQ29tcHV0ZXIgU2NpZW5jZSBDb3Jwb3JhdGlvbiBMaW1pdGVkIiwidXNlcm5hbWUiOiJhZG1pbiJ9.Um39_CTM01n1g4XpFyuAa3VPxOozNPnJ0mu7kxU6KUs"
,
"MYJOB"
:
"
eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBdXRoIiwidWlkIjoiOGFhNDUzMzAtMzE0Yy0xMWU3LWJhZjMtMmQ3ZDA5ODc3NzQ0Iiwicm9sZXMiOlsiYWRtaW4iXSwiaXNzIjoiQ29tcHV0ZXIgU2NpZW5jZSBDb3Jwb3JhdGlvbiBMaW1pdGVkIiwidXNlcm5hbWUiOiJhZG1pbiJ9.Um39_CTM01n1g4XpFyuAa3VPxOozNPnJ0mu7kxU6KUs
"
,
"MYJOB"
:
""
,
"MYSKILL-X"
:
"eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBdXRoIiwidWlkIjoiOGFhNDUzMzAtMzE0Yy0xMWU3LWJhZjMtMmQ3ZDA5ODc3NzQ0Iiwicm9sZXMiOlsiYWRtaW4iXSwiaXNzIjoiQ29tcHV0ZXIgU2NpZW5jZSBDb3Jwb3JhdGlvbiBMaW1pdGVkIiwidXNlcm5hbWUiOiJhZG1pbiJ9.Um39_CTM01n1g4XpFyuAa3VPxOozNPnJ0mu7kxU6KUs"
,
}
...
...
@@ -113,7 +116,7 @@ export class TokenService {
},
}
constructor
(
private
router
:
Router
)
{
}
constructor
(
private
router
:
Router
,
private
http
:
HttpClient
)
{
}
signOut
():
void
{
window
.
localStorage
.
clear
();
...
...
@@ -198,18 +201,56 @@ export class TokenService {
return
new
CompanyModel
();
}
public
saveAppToken
(
module
:
string
):
void
{
let
tokenkey
=
this
.
apptoken
[
module
]
public
saveAppToken
(
module
:
string
,
token
?:
string
):
Observable
<
any
>
{
if
(
module
===
'MYJOB'
)
{
const
modulesData
=
this
.
getModulesData
()
as
any
;
const
myjobModule
=
modulesData
?.
modules
?.
find
((
m
:
{
app
:
string
;
})
=>
m
.
app
===
'MYJOB'
);
const
refreshToken
=
myjobModule
?
myjobModule
.
refreshToken
:
null
;
if
(
!
refreshToken
)
{
console
.
error
(
'MYJOB Refresh Token not found in modules data! Falling back to legacy method.'
);
this
.
executeLegacySave
(
module
,
token
);
return
of
(
null
);
}
return
this
.
http
.
post
<
any
>
(
environment
.
baseUrl
+
"/auth/portal/refresh-token"
,
{
"refreshToken"
:
refreshToken
}).
pipe
(
tap
(
response
=>
{
if
(
response
&&
response
.
accessToken
)
{
this
.
saveTokenToStorage
(
module
,
response
.
accessToken
);
}
else
{
console
.
error
(
'accessToken not found in postPortalRefreshToken response for MYJOB. Falling back to legacy method.'
);
this
.
executeLegacySave
(
module
,
token
);
}
})
);
}
else
{
this
.
executeLegacySave
(
module
,
token
);
return
of
(
null
);
}
}
private
executeLegacySave
(
module
:
string
,
token
?:
string
):
void
{
const
tokenkey
=
token
||
this
.
apptoken
[
module
];
this
.
saveTokenToStorage
(
module
,
tokenkey
);
}
private
saveTokenToStorage
(
module
:
string
,
tokenkey
:
string
|
null
):
void
{
if
(
tokenkey
&&
tokenkey
.
startsWith
(
'Bearer '
))
{
tokenkey
=
tokenkey
.
substring
(
7
);
}
window
.
sessionStorage
.
setItem
(
"module"
,
module
);
// window.localStorage.removeItem(APP_TOKEN_KEY);
// window.localStorage.setItem(APP_TOKEN_KEY, tokenkey);
window
.
sessionStorage
.
removeItem
(
APP_TOKEN_KEY
);
if
(
tokenkey
)
{
window
.
sessionStorage
.
setItem
(
APP_TOKEN_KEY
,
tokenkey
);
let
db
=
this
.
dbApp
[
module
]
}
const
db
=
this
.
dbApp
[
module
];
if
(
db
)
{
window
.
localStorage
.
removeItem
(
COMPANY
);
window
.
localStorage
.
setItem
(
COMPANY
,
JSON
.
stringify
(
new
CompanyModel
(
db
)));
}
}
public
getAppToken
():
string
|
null
{
// return window.localStorage.getItem(APP_TOKEN_KEY);
...
...
@@ -221,4 +262,31 @@ export class TokenService {
return
window
.
sessionStorage
.
getItem
(
"module"
);
}
public
saveModulesData
(
modules
:
any
[]):
void
{
window
.
sessionStorage
.
removeItem
(
MODULE_KEY
);
window
.
sessionStorage
.
setItem
(
MODULE_KEY
,
JSON
.
stringify
(
modules
));
}
public
getModulesData
():
any
[]
|
null
{
const
data
=
window
.
sessionStorage
.
getItem
(
MODULE_KEY
);
if
(
data
)
{
return
JSON
.
parse
(
data
);
}
return
null
;
}
public
saveAppAccessToken
(
module
:
string
,
accessToken
:
string
):
void
{
if
(
!
module
||
!
accessToken
)
return
;
let
token
=
accessToken
;
if
(
token
.
startsWith
(
'Bearer '
))
{
token
=
token
.
substring
(
7
);
}
window
.
sessionStorage
.
setItem
(
`accessToken-
${
module
}
`
,
token
);
}
public
getAppAccessToken
(
module
:
string
):
string
|
null
{
if
(
!
module
)
return
null
;
return
window
.
sessionStorage
.
getItem
(
`accessToken-
${
module
}
`
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment