aws-amplify#Cache JavaScript Examples

The following examples show how to use aws-amplify#Cache. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LoginForm.js    From vch-mri with MIT License 6 votes vote down vote up
async handleSubmit(e) {
        e.preventDefault();
        const { history } = this.props;
        this.setState({ loading: true });
        try {
            const user = await Auth.signIn(this.state.email.trim(), this.state.password.trim());
            const accessToken = user.signInUserSession.accessToken.jwtToken;
            const idToken = user.signInUserSession.idToken.jwtToken;
            Cache.setItem(AUTH_USER_ACCESS_TOKEN_KEY, accessToken);
            Cache.setItem(AUTH_USER_ID_TOKEN_KEY, idToken);
            this.props.loginSuccess(user);
            history.push('/dashboard');
        } catch(e) {
            //this.props.loginFailure(e.message);
            this.setState({ error: e.message, loading: false, email:'', password:'' });
        }
    }
Example #2
Source File: Navbar.js    From vch-mri with MIT License 6 votes vote down vote up
async handleLogout() {
        const { history } = this.props;
        try {
            await Auth.signOut({global: true});
            Cache.removeItem(AUTH_USER_ACCESS_TOKEN_KEY);
            Cache.removeItem(AUTH_USER_ID_TOKEN_KEY);
            this.props.logout();
            history.push('/login');
        } catch (e) {
            console.log('error signing out: ', e);
        }
    }
Example #3
Source File: PrivateRoute.js    From vch-mri with MIT License 6 votes vote down vote up
PrivateRoute = ({ component: Component, authentication, ...rest }) => {
    const checkUserAuth = validateToken(Cache.getItem(AUTH_USER_ACCESS_TOKEN_KEY));

    return (<Route
        {...rest}
        render={props =>
            checkUserAuth ? (
                <Component {...props} />
            ) : (
                <Redirect to="/login"/>
            )
        }
    />);
}
Example #4
Source File: AuthenticationReducer.js    From vch-mri with MIT License 6 votes vote down vote up
authentication = (state = initialState, action) => {
    switch (action.type) {
        case userConstants.LOGIN_SUCCESS:
            return {
                ...state,
                loggedIn: true,
                user: {
                    name: action.name,
                    email: action.email
                },
                error: ""
            };
        case userConstants.LOGIN_FAILURE:
            return {
                ...state,
                loggedIn: false,
                error: action.error
            };
        case userConstants.LOGOUT:
            return {
                ...state,
                loggedIn: false,
                user: {},
            };
        case userConstants.GET_USER_INFO:
            let storedUser = JSON.parse(Cache.getItem(AUTH_USER_ID_TOKEN_KEY));
            return {
                ...state,
                user: {
                    name: storedUser.name,
                    email: storedUser.email
                },
            };
        default:
            return state
    }
}
Example #5
Source File: HomePage.js    From vch-mri with MIT License 5 votes vote down vote up
render() {
        const user = jwt_decode(Cache.getItem(AUTH_USER_ID_TOKEN_KEY));
        return (
            <div className='page-container'>
                <Grid centered>
                    <Grid.Row centered>
                        <Container text>
                            <Header as='h1' style={{ fontSize: '2em', paddingTop: '0.75em',}}>
                                {`Welcome back, ${this.props.auth.user.name ? this.props.auth.user.name : user.name}!`}
                            </Header>
                        </Container>
                    </Grid.Row>
                    <Grid.Row centered style={{ paddingBottom: '4em',}}>
                        <Button
                            color='blue'
                            size='huge'
                            onClick={this.handleClick}
                            icon
                            labelPosition='right'
                        >
                            <Icon name='arrow circle right'/> Book an MRI
                        </Button>
                    </Grid.Row>
                    <Grid.Row centered>
                        <StatisticGroup>
                            <Statistic>
                                <Statistic.Value>{this.props.info.daily}</Statistic.Value>
                                <Statistic.Label>Forms processed today</Statistic.Label>
                            </Statistic>
                            <Statistic>
                                <Statistic.Value>{this.props.info.weekly}</Statistic.Value>
                                <Statistic.Label>Forms processed this week</Statistic.Label>
                            </Statistic>
                            <Statistic>
                                <Statistic.Value>{this.props.info.monthly}</Statistic.Value>
                                <Statistic.Label>Forms processed this month</Statistic.Label>
                            </Statistic>
                        </StatisticGroup>
                    </Grid.Row>
                </Grid>
            </div>
        )
    }