-
Notifications
You must be signed in to change notification settings - Fork 10
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 does not have access to prisma.public #52
Comments
Hello @mattruddy ! I plan to update to new Prisma this week. And then i check your issue in new version. Stay tuned :D |
@wangel13 awesome news! This is a really great template. Its really the only of its kind. If you have time can you add a user profile query? I'm having trouble getting the session for a user and the rest of their profile on a query. Think if there was a Thanks again |
Would export const createContext = async ({ res, req }): Promise<Context> => {
const session = await getSession({ req });
return {prisma, res, req, session };
} I'm guessing we would have to extend the Context interface too since session is not a part of it |
graphql-nexus/nexus-plugin-prisma#1039 (comment) Ok I get it now. so you use next-auth api to get a session and then use next-auth/client in |
You can use shield for some checks like
in example query - yes, but you can write your own rules |
ahh now I get it. I should have read the docs for |
const isAuthenticated = rule({ cache: 'contextual' })(async (parent, args, ctx, info) => {
return ctx.user !== null
})
const isAdmin = rule({ cache: 'contextual' })(async (parent, args, ctx, info) => {
return ctx.user.role === 'admin'
})
const isEditor = rule({ cache: 'contextual' })(async (parent, args, ctx, info) => {
return ctx.user.role === 'editor'
})
// Permissions
const permissions = shield({
Query: {
frontPage: not(isAuthenticated),
fruits: and(isAuthenticated, or(isAdmin, isEditor)),
customers: and(isAuthenticated, isAdmin),
},
Mutation: {
addFruitToBasket: isAuthenticated,
},
Fruit: isAuthenticated,
Customer: isAdmin,
}) |
Awesome I guess the only question still is how do I get a reference to the signed in user in the resolver? export const Queries = extendType({
type: 'Query',
definition: (t) => {
t.field('example', {
type: 'Example',
resolve: async (_parent, _args, _ctx) => {
return {
message: 'Hello there!',
}
},
})
},
}) |
Like this: export const Queries = extendType({
type: 'Query',
definition: (t) => {
t.field('example', {
type: 'Example',
resolve: async (_parent, _args, _ctx) => {
const session = await getSession({ req: _ctx.req })
console.log(session)
return {
message: 'Hello there!',
}
},
})
},
}) |
and don't forget, you have |
Thanks this helps a lot |
Feel free to ask ;) |
export const Queries = extendType({
type: 'Query',
definition: (t) => {
t.field('example', {
type: 'Example',
resolve: async (_parent, _args, {req, prisma}) => {
const session = await getSession({ req: _ctx.req })
return await prisma.user.findFirst()
.where ({
email: session?.user?.email
})
},
})
},
}) so something like that |
@mattruddy Check new version plz.. |
hey @wangel13 this is really helpful. found this while searching on sourcegraph. i've copied your code but i am unable to access can you tell me what i'm doing wrong? struggling to # Write your query or mutation here
{
currentUser(id: "ckv226a840006k9v5ua3xvgsk") {
id
name
username
email
}
} despite my code looks similar to yours. |
Hello! I think this problem connected with maticzav/graphql-middleware#433 |
I keep getting an error when ever starting up the application that the user doesnt have access to the database. Any idea what this could be?
Authentication failed against database server at 'localhost', the provided database credentials for 'johndoe' are not valid.
The text was updated successfully, but these errors were encountered: