@@ -9,7 +9,7 @@ function isValidHttpUrl(string) {
99 try {
1010 const url = new URL ( string ) ;
1111 return url . protocol === "http:" || url . protocol === "https:" ;
12- } catch {
12+ } catch ( _ ) {
1313 return false ;
1414 }
1515}
@@ -31,23 +31,31 @@ export function useLogin() {
3131 try {
3232 const responseData = await securityService . login ( payload ) ;
3333
34- // Step 1: Handle 2FA
34+ // Check if the backend demands 2FA and no TOTP was provided yet
3535 if ( responseData . requires2FA && ! payload . totp ) {
3636 requires2FA . value = true ;
3737 return { success : false , requires2FA : true } ;
3838 }
3939
40- // Step 2: Handle explicit error message
40+ // Check rotate password flow
41+ if ( responseData . rotate_password && responseData . redirect ) {
42+ window . location . href = responseData . redirect ;
43+ return { success : true , rotate : true } ;
44+ }
45+
46+ // Handle explicit backend error message
4147 if ( responseData . error ) {
4248 showErrorNotification ( responseData . error ) ;
4349 return { success : false , error : responseData . error } ;
4450 }
4551
46- // Step 3: Set user and load platform config
47- securityStore . setUser ( responseData ) ;
48- await platformConfigurationStore . initialize ( ) ;
52+ // Special flow for terms acceptance
53+ if ( responseData . load_terms && responseData . redirect ) {
54+ window . location . href = responseData . redirect ;
55+ return { success : true , redirect : responseData . redirect } ;
56+ }
4957
50- // Step 4: Honor a redirect query parameter
58+ // Handle external redirect param
5159 const redirectParam = route . query . redirect ?. toString ( ) ;
5260 if ( redirectParam ) {
5361 if ( isValidHttpUrl ( redirectParam ) ) {
@@ -58,39 +66,43 @@ export function useLogin() {
5866 return { success : true } ;
5967 }
6068
61- // Step 5: Handle "load terms" flow
62- if ( responseData . load_terms && responseData . redirect ) {
69+ if ( responseData . redirect ) {
6370 window . location . href = responseData . redirect ;
6471 return { success : true } ;
6572 }
6673
67- // Step 6: Default post-login redirect based on roles
68- const setting = platformConfigurationStore . getSetting (
69- "registration.redirect_after_login"
70- ) ;
74+ securityStore . setUser ( responseData ) ;
75+ await platformConfigurationStore . initialize ( ) ;
76+
77+ // Handle redirect param again after login
78+ if ( route . query . redirect ) {
79+ await router . replace ( { path : route . query . redirect . toString ( ) } ) ;
80+ return { success : true } ;
81+ }
82+
83+ // Determine post-login route from settings
84+ const setting = platformConfigurationStore . getSetting ( "registration.redirect_after_login" ) ;
7185 let target = "/" ;
7286
7387 if ( setting && typeof setting === "string" ) {
7488 try {
7589 const map = JSON . parse ( setting ) ;
7690 const roles = responseData . roles || [ ] ;
77- const profile = roles . includes ( "ROLE_ADMIN" )
78- ? "ADMIN"
79- : roles . includes ( "ROLE_SESSION_MANAGER" )
80- ? "SESSIONADMIN"
81- : roles . includes ( "ROLE_TEACHER" )
82- ? "COURSEMANAGER"
83- : roles . includes ( "ROLE_STUDENT_BOSS" )
84- ? "STUDENT_BOSS"
85- : roles . includes ( "ROLE_DRH" )
86- ? "DRH"
87- : roles . includes ( "ROLE_INVITEE" )
88- ? "INVITEE"
89- : roles . includes ( "ROLE_STUDENT" )
90- ? "STUDENT"
91- : null ;
9291
92+ const getProfile = ( ) => {
93+ if ( roles . includes ( "ROLE_ADMIN" ) ) return "ADMIN" ;
94+ if ( roles . includes ( "ROLE_SESSION_MANAGER" ) ) return "SESSIONADMIN" ;
95+ if ( roles . includes ( "ROLE_TEACHER" ) ) return "COURSEMANAGER" ;
96+ if ( roles . includes ( "ROLE_STUDENT_BOSS" ) ) return "STUDENT_BOSS" ;
97+ if ( roles . includes ( "ROLE_DRH" ) ) return "DRH" ;
98+ if ( roles . includes ( "ROLE_INVITEE" ) ) return "INVITEE" ;
99+ if ( roles . includes ( "ROLE_STUDENT" ) ) return "STUDENT" ;
100+ return null ;
101+ } ;
102+
103+ const profile = getProfile ( ) ;
93104 const value = profile && map [ profile ] ? map [ profile ] : "" ;
105+
94106 switch ( value ) {
95107 case "user_portal.php" :
96108 case "index.php" :
0 commit comments