File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change 6
6
"react-scripts" : " 0.9.5"
7
7
},
8
8
"dependencies" : {
9
+ "base64-js" : " ^1.2.1" ,
9
10
"jwt-decode" : " ^2.2.0" ,
10
11
"react" : " ^15.5.4" ,
11
12
"react-dom" : " ^15.5.4" ,
14
15
"redux" : " ^3.6.0" ,
15
16
"redux-form" : " ^6.6.3" ,
16
17
"redux-thunk" : " ^2.2.0" ,
18
+ "text-encoding" : " ^0.6.4" ,
17
19
"validator" : " ^7.0.0"
18
20
},
19
21
"scripts" : {
Original file line number Diff line number Diff line change 1
1
import jwtDecode from 'jwt-decode' ;
2
2
import { SubmissionError } from 'redux-form' ;
3
+ import { fromByteArray } from 'base64-js' ;
4
+ import { TextEncoder } from 'text-encoding' ;
3
5
4
6
import { API_BASE_URL } from '../config' ;
5
7
import { normalizeResponseErrors } from './utils' ;
@@ -17,6 +19,13 @@ export const setCurrentUser = currentUser => ({
17
19
currentUser
18
20
} ) ;
19
21
22
+ // Encode a JS string as Base-64 encoded UTF-8
23
+ const base64EncodingUTF8 = str => {
24
+ const encoded = new TextEncoder ( 'utf-8' ) . encode ( str ) ;
25
+ const b64Encoded = fromByteArray ( encoded ) ;
26
+ return b64Encoded ;
27
+ } ;
28
+
20
29
// Stores the auth token in state and localStorage, and decodes and stores
21
30
// the user data stored in the token
22
31
const storeAuthInfo = ( authToken , dispatch ) => {
@@ -29,7 +38,7 @@ const storeAuthInfo = (authToken, dispatch) => {
29
38
export const login = ( username , password ) => dispatch => {
30
39
// Base64 encode the string username:password, used in the basic
31
40
// auth field
32
- const token = btoa ( `${ username } :${ password } ` ) ;
41
+ const token = base64EncodingUTF8 ( `${ username } :${ password } ` ) ;
33
42
return (
34
43
fetch ( `${ API_BASE_URL } /auth/login` , {
35
44
method : 'POST' ,
Original file line number Diff line number Diff line change @@ -889,6 +889,10 @@ base64-js@^1.0.2:
889
889
version "1.2.0"
890
890
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.2.0.tgz#a39992d723584811982be5e290bb6a53d86700f1"
891
891
892
+ base64-js@^1.2.1 :
893
+ version "1.2.1"
894
+ resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.2.1.tgz#a91947da1f4a516ea38e5b4ec0ec3773675e0886"
895
+
892
896
893
897
version "0.5.3"
894
898
resolved "https://registry.yarnpkg.com/batch/-/batch-0.5.3.tgz#3f3414f380321743bfc1042f9a83ff1d5824d464"
@@ -4958,6 +4962,10 @@ test-exclude@^3.3.0:
4958
4962
read-pkg-up "^1.0.1"
4959
4963
require-main-filename "^1.0.1"
4960
4964
4965
+ text-encoding@^0.6.4 :
4966
+ version "0.6.4"
4967
+ resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.6.4.tgz#e399a982257a276dae428bb92845cb71bdc26d19"
4968
+
4961
4969
text-table@~0.2.0 :
4962
4970
version "0.2.0"
4963
4971
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
You can’t perform that action at this time.
0 commit comments