@@ -3,10 +3,10 @@ import jwt from 'jsonwebtoken';
33const STORAGE_KEY = 'mock-amplify-auth.state' ;
44const USER_ID_PREFIX = 'mock-auth-' ;
55
6- let authState ;
6+ let authState : any ;
77
88try {
9- authState = JSON . parse ( window . localStorage . getItem ( STORAGE_KEY ) ) || { } ;
9+ authState = JSON . parse ( window . localStorage . getItem ( STORAGE_KEY ) as any ) || { } ;
1010} catch ( err ) {
1111 authState = { } ;
1212}
@@ -21,12 +21,12 @@ export const Auth = {
2121 extractEmail
2222} ;
2323
24- function signUp ( email ) {
24+ function signUp ( email : string ) {
2525 updateState ( { email, loggedIn : false } ) ;
2626 return timerPromise ( 1200 ) ;
2727}
2828
29- function signIn ( email ) {
29+ function signIn ( email : string ) {
3030 updateState ( { email, session : createSession ( { email } ) , loggedIn : true } ) ;
3131 return timerPromise ( 700 ) ;
3232}
@@ -48,12 +48,12 @@ function resendSignUp() {
4848 return timerPromise ( 100 ) ;
4949}
5050
51- function updateState ( newState ) {
51+ function updateState ( newState : any ) {
5252 Object . assign ( authState , newState ) ;
5353 window . localStorage . setItem ( STORAGE_KEY , JSON . stringify ( authState ) ) ;
5454}
5555
56- function timerPromise ( ms , success = true , arg = { } ) {
56+ function timerPromise ( ms : number , success = true , arg = { } ) {
5757 if ( ! success && ! arg ) {
5858 arg = new Error ( ) ;
5959 }
@@ -62,16 +62,16 @@ function timerPromise(ms, success = true, arg = {}) {
6262 ) ;
6363}
6464
65- function extractEmail ( userId ) {
65+ function extractEmail ( userId : string ) {
6666 return Buffer . from (
6767 userId . substring ( USER_ID_PREFIX . length ) ,
6868 "base64"
6969 ) . toString ( ) ;
7070}
7171
72- function createSession ( { email } ) {
72+ function createSession ( args : { email : string } ) {
7373 const timeS = Math . floor ( Date . now ( ) / 1000 ) ;
74- const cognitoUsername = `${ USER_ID_PREFIX } ${ Buffer . from ( email ) . toString (
74+ const cognitoUsername = `${ USER_ID_PREFIX } ${ Buffer . from ( args . email ) . toString (
7575 "base64"
7676 ) } `;
7777 const idTokenPayload = {
@@ -84,7 +84,7 @@ function createSession({ email }) {
8484 exp : timeS + 100000 ,
8585 iss : "https://cognito-idp.local.amazonaws.com/local_mock-auth" ,
8686 "cognito:username" : cognitoUsername ,
87- email
87+ email : args . email
8888 } ;
8989 const idToken = {
9090 jwtToken : jwt . sign ( idTokenPayload , "mock-auth-secret" ) ,
0 commit comments