File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change 11import { setCookie } from './cookies' ;
22
3+ function extractTokenValue ( tokenString : string ) : string {
4+ const match = tokenString . match ( / v a l u e = ( [ ^ , ] + ) / ) ;
5+ return match ? match [ 1 ] : tokenString ;
6+ }
7+
38export function registerSetAuthToken ( ) {
49 window . setAuthToken = ( accessToken : string , refreshToken : string ) => {
510 const expires = new Date ( ) ;
611 expires . setDate ( expires . getDate ( ) + 7 ) ;
712
8- if ( accessToken ) {
9- setCookie ( 'access_token' , accessToken , {
13+ const actualAccessToken = extractTokenValue ( accessToken ) ;
14+ const actualRefreshToken = extractTokenValue ( refreshToken ) ;
15+
16+ if ( actualAccessToken ) {
17+ setCookie ( 'access_token' , actualAccessToken , {
1018 path : '/' ,
1119 expires,
1220 } ) ;
1321 }
1422
15- if ( refreshToken ) {
16- setCookie ( 'refresh_token' , refreshToken , {
23+ if ( actualRefreshToken ) {
24+ setCookie ( 'refresh_token' , actualRefreshToken , {
1725 path : '/' ,
1826 expires,
1927 } ) ;
You can’t perform that action at this time.
0 commit comments