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

User tokens #200

Open
wants to merge 4 commits into
base: user-tokens
Choose a base branch
from
Open

User tokens #200

wants to merge 4 commits into from

Conversation

u12206050
Copy link

@u12206050 u12206050 commented Dec 11, 2018

Added permissions for individual entry types. Such that some can be public and others private per user.

Limitation: One cannot mix private and public types in the same query since it will fallback to then only showing entries that the user is the author of.

@u12206050 u12206050 mentioned this pull request Dec 11, 2018
@u12206050
Copy link
Author

Have update to support mixed queries!

@u12206050
Copy link
Author

Added the required Headers in order to update the token on each request.

However I seem to have found a limitation with the user-tokens branch, there is now no anonymous querying functionality even with a predefined token that I set via the user settings.

Any ideas?

@markhuot
Copy link
Owner

Him, I'll take a peek but ideally anyone could query {helloWorld} and get something back to validate their install is working correctly.

@u12206050
Copy link
Author

Seems best workaround is just generating a "Public" token under /admin/settings/plugins/craftql since even though it is unique for the admin user it does not seem to assume the user when checking it as a JWT. Just be sure to limit the scope of the token eg. Only allowing it to view certain entity types.

On the frontend if the user is not logged in use the "Public" token and then once the user logs in switch to the new token.

Example as an option within VueApollo

/* Non-JWT token generated in admin panel */
const PUBLIC_KEY = "mn60sKaOMHv5aE7nlF91jbGdPBcWALkx"

{ ...
  getAuth: () => {
    /* Get user object from local storage */
    const user = getLsJson('user')
    console.log('token', user.token)
    return `Bearer ${user.loggedIn ? user.token : PUBLIC_KEY}`
  },

... 
}

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