Skip to content

Commit

Permalink
field-permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
benawad committed Aug 14, 2020
1 parent 38456e1 commit dcb28a1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion server/src/resolvers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
Ctx,
ObjectType,
Query,
FieldResolver,
Root,
} from "type-graphql";
import { MyContext } from "../types";
import { User } from "../entities/User";
Expand Down Expand Up @@ -34,8 +36,18 @@ class UserResponse {
user?: User;
}

@Resolver()
@Resolver(User)
export class UserResolver {
@FieldResolver(() => String)
email(@Root() user: User, @Ctx() { req }: MyContext) {
// this is the current user and its ok to show them their own email
if (req.session.userId === user.id) {
return user.email;
}
// current user wants to see someone elses email
return "";
}

@Mutation(() => UserResponse)
async changePassword(
@Arg("token") token: string,
Expand Down

0 comments on commit dcb28a1

Please sign in to comment.