@@ -6,10 +6,8 @@ import { DecodedPayloadOutputComponent } from "@/features/decoder/components/dec
66import { JwtInputComponent } from "@/features/decoder/components/jwt-input.component" ;
77import { SecretKeyInputComponent } from "@/features/decoder/components/secret-key-input.component" ;
88import { useDecoderStore } from "@/features/decoder/services/decoder.store" ;
9- import { useRouter } from "next/navigation" ;
10- import {
11- SupportedTokenHashParamValues
12- } from "@/libs/config/project.constants" ;
9+ import { usePathname , useRouter , useSearchParams } from "next/navigation" ;
10+ import { SupportedTokenHashParamValues } from "@/libs/config/project.constants" ;
1311import { HomeDictionaryModel } from "@/features/localization/models/home-dictionary.model" ;
1412import { ClaimDescriptionVisibilityValues } from "@/features/common/values/claim-description-visibility.values" ;
1513import { useDebuggerStore } from "@/features/debugger/services/debugger.store" ;
@@ -41,6 +39,8 @@ export const TokenDecoderComponent: React.FC<TokenDecoderComponentProps> = ({
4139 headlineConfig,
4240} ) => {
4341 const isMounted = useRef ( false ) ;
42+ const searchParams = useSearchParams ( ) ;
43+ const pathname = usePathname ( ) ;
4444
4545 const router = useRouter ( ) ;
4646
@@ -51,8 +51,25 @@ export const TokenDecoderComponent: React.FC<TokenDecoderComponentProps> = ({
5151
5252 useEffect ( ( ) => {
5353 const handleHashChange = ( ) => {
54- console . count ( "hash handler fired" )
55- const hash = window . location . hash . substring ( 1 ) ;
54+ const tokenParam =
55+ searchParams . get ( "token" ) ||
56+ searchParams . get ( "id_token" ) ||
57+ searchParams . get ( "access_token" ) ||
58+ searchParams . get ( "value" ) ;
59+ const isHomePage = pathname === "/" ;
60+ const hash = tokenParam
61+ ? `token=${ tokenParam } `
62+ : window . location . hash . substring ( 1 ) ;
63+
64+ if ( tokenParam && isHomePage ) {
65+ const currentParams = new URLSearchParams ( searchParams . toString ( ) ) ;
66+ currentParams . delete ( "token" ) ;
67+ currentParams . delete ( "id_token" ) ;
68+ currentParams . delete ( "access_token" ) ;
69+ currentParams . delete ( "value" ) ;
70+ router . replace ( `${ pathname } #${ hash } ` ) ;
71+ }
72+ console . count ( "hash handler fired" ) ;
5673
5774 if ( hash . includes ( "debugger-io?token=" ) ) {
5875 const debugHash = window . location . hash
@@ -68,34 +85,32 @@ export const TokenDecoderComponent: React.FC<TokenDecoderComponentProps> = ({
6885 }
6986
7087 const newUrl = `${ currentUrl } #${ SupportedTokenHashParamValues . TOKEN } =${ token } ` ;
71- console . log ( "Logging hash length before replacing///" , token . length )
88+ console . log ( "Logging hash length before replacing///" , token . length ) ;
7289 window . location . replace ( newUrl ) ;
7390
7491 return ;
7592 }
7693
7794 if ( ! hash . includes ( "=" ) ) {
78- console . log ( "hash not includes =" )
95+ console . log ( "hash not includes =" ) ;
7996 return ;
8097 }
8198
82-
83-
8499 const hashParams = new URLSearchParams ( hash ) ;
85- console . log ( "Hash param keys!!!" , hashParams )
100+ console . log ( "Hash param keys!!!" , hashParams ) ;
86101 Object . values ( SupportedTokenHashParamValues ) . forEach ( ( hashParamKey ) => {
87102 const token = hashParams . get ( hashParamKey ) ;
88103
89104 if ( token ) {
90- console . count ( "handling jwt change" )
91- console . log ( "The token is:///" , token )
105+ console . count ( "handling jwt change" ) ;
106+ console . log ( "The token is:///" , token ) ;
92107 handleJwtChange$ ( token ) ;
93108 }
94109 } ) ;
95110 } ;
96111
97112 window . addEventListener ( "hashchange" , handleHashChange ) ;
98-
113+
99114 handleHashChange ( ) ;
100115
101116 return ( ) => {
0 commit comments