Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace authProvider function by object #3694

Merged
merged 7 commits into from
Sep 16, 2019
Merged

Replace authProvider function by object #3694

merged 7 commits into from
Sep 16, 2019

Conversation

fzaninotto
Copy link
Member

Refs #3686

Example of authProvider with the new signature:

export default {
    login: ({ username, password }) => {
        if (username === 'login' && password === 'password') {
            localStorage.removeItem('not_authenticated');
            localStorage.removeItem('role');
            return Promise.resolve();
        }
        if (username === 'user' && password === 'password') {
            localStorage.setItem('role', 'user');
            localStorage.removeItem('not_authenticated');
            return Promise.resolve();
        }
        if (username === 'admin' && password === 'password') {
            localStorage.setItem('role', 'admin');
            localStorage.removeItem('not_authenticated');
            return Promise.resolve();
        }
        localStorage.setItem('not_authenticated', true);
        return Promise.reject();
    },
    logout: () => {
        localStorage.setItem('not_authenticated', true);
        localStorage.removeItem('role');
        return Promise.resolve();
    },
    checkError: ({ status }) => {
        return status === 401 || status === 403
            ? Promise.reject()
            : Promise.resolve();
    },
    checkAuth: () => {
        return localStorage.getItem('not_authenticated')
            ? Promise.reject()
            : Promise.resolve();
    },
    getPermissions: () => {
        const role = localStorage.getItem('role');
        return Promise.resolve(role);
    },
};

This change is backward compatible

@fzaninotto fzaninotto added this to the 3.0.0 milestone Sep 16, 2019
docs/Authentication.md Outdated Show resolved Hide resolved
Co-Authored-By: Gildas Garcia <[email protected]>
@djhi djhi merged commit 902cb85 into next Sep 16, 2019
@djhi djhi deleted the authProvider-object branch September 16, 2019 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants