@@ -42,7 +42,11 @@ export const exchangeAuthCode = async ({
42
42
43
43
const activeStorage = getActiveStorage ( ) ;
44
44
if ( ! activeStorage ) {
45
- throw new Error ( "No active storage found" ) ;
45
+ console . error ( "No active storage found" ) ;
46
+ return {
47
+ success : false ,
48
+ error : `Authentication storage is not initialized` ,
49
+ } ;
46
50
}
47
51
48
52
// warn if framework and version has not been set
@@ -65,8 +69,15 @@ export const exchangeAuthCode = async ({
65
69
StorageKeys . codeVerifier ,
66
70
) ) as string ;
67
71
68
- const headers : { "Content-type" : string ; "Kinde-SDK" ?: string } = {
72
+ const headers : {
73
+ "Content-type" : string ;
74
+ "Cache-Control" : string ;
75
+ Pragma : string ;
76
+ "Kinde-SDK" ?: string ;
77
+ } = {
69
78
"Content-type" : "application/x-www-form-urlencoded; charset=UTF-8" ,
79
+ "Cache-Control" : "no-store" ,
80
+ Pragma : "no-cache" ,
70
81
} ;
71
82
72
83
if ( frameworkSettings . framework ) {
@@ -89,7 +100,7 @@ export const exchangeAuthCode = async ({
89
100
} ) ;
90
101
if ( ! response ?. ok ) {
91
102
const errorText = await response . text ( ) ;
92
- console . error ( ' Token exchange failed:' , response . status , errorText ) ;
103
+ console . error ( " Token exchange failed:" , response . status , errorText ) ;
93
104
return {
94
105
success : false ,
95
106
error : `Token exchange failed: ${ response . status } - ${ errorText } ` ,
@@ -111,9 +122,14 @@ export const exchangeAuthCode = async ({
111
122
await activeStorage . removeItems ( StorageKeys . state , StorageKeys . codeVerifier ) ;
112
123
113
124
// Clear all url params
114
- const url = new URL ( window . location . toString ( ) ) ;
115
- url . search = "" ;
116
- window . history . pushState ( { } , "" , url ) ;
125
+ const cleanUrl = ( url : URL ) : URL => {
126
+ url . search = "" ;
127
+ url . hash = "" ;
128
+ return url ;
129
+ } ;
130
+ const url = cleanUrl ( new URL ( window . location . toString ( ) ) ) ;
131
+ // Replace current state and clear forward history
132
+ window . history . replaceState ( null , "" , url ) ;
117
133
118
134
return {
119
135
success : true ,
0 commit comments