Skip to content

Commit

Permalink
Merge pull request #37 from redacademy/af-bugfix-auth
Browse files Browse the repository at this point in the history
resolve auth bug
  • Loading branch information
siddharthparmar7 authored Dec 5, 2019
2 parents 9e0e37b + 31476c8 commit 09b97c3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 62 deletions.
32 changes: 3 additions & 29 deletions server/src/generated/prisma-client/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,6 @@ export type UserOrderByInput =
| "location_DESC"
| "image_ASC"
| "image_DESC"
| "bio_ASC"
| "bio_DESC"
| "date_ASC"
| "date_DESC";

Expand Down Expand Up @@ -1119,7 +1117,6 @@ export interface UserUpdateManyMutationInput {
lastName?: Maybe<String>;
location?: Maybe<String>;
image?: Maybe<String>;
bio?: Maybe<String>;
}

export interface UserWhereInput {
Expand Down Expand Up @@ -1221,20 +1218,6 @@ export interface UserWhereInput {
image_not_starts_with?: Maybe<String>;
image_ends_with?: Maybe<String>;
image_not_ends_with?: Maybe<String>;
bio?: Maybe<String>;
bio_not?: Maybe<String>;
bio_in?: Maybe<String[] | String>;
bio_not_in?: Maybe<String[] | String>;
bio_lt?: Maybe<String>;
bio_lte?: Maybe<String>;
bio_gt?: Maybe<String>;
bio_gte?: Maybe<String>;
bio_contains?: Maybe<String>;
bio_not_contains?: Maybe<String>;
bio_starts_with?: Maybe<String>;
bio_not_starts_with?: Maybe<String>;
bio_ends_with?: Maybe<String>;
bio_not_ends_with?: Maybe<String>;
date?: Maybe<DateTimeInput>;
date_not?: Maybe<DateTimeInput>;
date_in?: Maybe<DateTimeInput[] | DateTimeInput>;
Expand Down Expand Up @@ -1430,8 +1413,7 @@ export interface UserCreateInput {
firstName: String;
lastName: String;
location: String;
image: String;
bio: String;
image?: Maybe<String>;
}

export interface FaqCreateManyInput {
Expand Down Expand Up @@ -1750,7 +1732,6 @@ export interface UserUpdateInput {
lastName?: Maybe<String>;
location?: Maybe<String>;
image?: Maybe<String>;
bio?: Maybe<String>;
}

export interface ContactInfoUpdateDataInput {
Expand Down Expand Up @@ -2328,8 +2309,7 @@ export interface UserPreviousValues {
firstName: String;
lastName: String;
location: String;
image: String;
bio: String;
image?: String;
date: DateTimeOutput;
}

Expand All @@ -2343,7 +2323,6 @@ export interface UserPreviousValuesPromise
lastName: () => Promise<String>;
location: () => Promise<String>;
image: () => Promise<String>;
bio: () => Promise<String>;
date: () => Promise<DateTimeOutput>;
}

Expand All @@ -2357,7 +2336,6 @@ export interface UserPreviousValuesSubscription
lastName: () => Promise<AsyncIterator<String>>;
location: () => Promise<AsyncIterator<String>>;
image: () => Promise<AsyncIterator<String>>;
bio: () => Promise<AsyncIterator<String>>;
date: () => Promise<AsyncIterator<DateTimeOutput>>;
}

Expand Down Expand Up @@ -2630,8 +2608,7 @@ export interface User {
firstName: String;
lastName: String;
location: String;
image: String;
bio: String;
image?: String;
date: DateTimeOutput;
}

Expand All @@ -2643,7 +2620,6 @@ export interface UserPromise extends Promise<User>, Fragmentable {
lastName: () => Promise<String>;
location: () => Promise<String>;
image: () => Promise<String>;
bio: () => Promise<String>;
date: () => Promise<DateTimeOutput>;
}

Expand All @@ -2657,7 +2633,6 @@ export interface UserSubscription
lastName: () => Promise<AsyncIterator<String>>;
location: () => Promise<AsyncIterator<String>>;
image: () => Promise<AsyncIterator<String>>;
bio: () => Promise<AsyncIterator<String>>;
date: () => Promise<AsyncIterator<DateTimeOutput>>;
}

Expand All @@ -2671,7 +2646,6 @@ export interface UserNullablePromise
lastName: () => Promise<String>;
location: () => Promise<String>;
image: () => Promise<String>;
bio: () => Promise<String>;
date: () => Promise<DateTimeOutput>;
}

Expand Down
27 changes: 3 additions & 24 deletions server/src/generated/prisma-client/prisma-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -2134,8 +2134,7 @@ type User {
firstName: String!
lastName: String!
location: String!
image: String!
bio: String!
image: String
date: DateTime!
}
Expand All @@ -2152,8 +2151,7 @@ input UserCreateInput {
firstName: String!
lastName: String!
location: String!
image: String!
bio: String!
image: String
}
type UserEdge {
Expand All @@ -2176,8 +2174,6 @@ enum UserOrderByInput {
location_DESC
image_ASC
image_DESC
bio_ASC
bio_DESC
date_ASC
date_DESC
}
Expand All @@ -2189,8 +2185,7 @@ type UserPreviousValues {
firstName: String!
lastName: String!
location: String!
image: String!
bio: String!
image: String
date: DateTime!
}
Expand Down Expand Up @@ -2219,7 +2214,6 @@ input UserUpdateInput {
lastName: String
location: String
image: String
bio: String
}
input UserUpdateManyMutationInput {
Expand All @@ -2229,7 +2223,6 @@ input UserUpdateManyMutationInput {
lastName: String
location: String
image: String
bio: String
}
input UserWhereInput {
Expand Down Expand Up @@ -2331,20 +2324,6 @@ input UserWhereInput {
image_not_starts_with: String
image_ends_with: String
image_not_ends_with: String
bio: String
bio_not: String
bio_in: [String!]
bio_not_in: [String!]
bio_lt: String
bio_lte: String
bio_gt: String
bio_gte: String
bio_contains: String
bio_not_contains: String
bio_starts_with: String
bio_not_starts_with: String
bio_ends_with: String
bio_not_ends_with: String
date: DateTime
date_not: DateTime
date_in: [DateTime!]
Expand Down
4 changes: 3 additions & 1 deletion server/src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ type AuthPayload {
type User {
id: ID!
email: String!
name: String!
firstName: String!
lastName: String!
location: String!
}
16 changes: 8 additions & 8 deletions server/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const jwt = require('jsonwebtoken')
const jwt = require("jsonwebtoken");

function getUserId(context) {
const Authorization = context.request.get('Authorization')
const Authorization = context.request.get("Authorization");
if (Authorization) {
const token = Authorization.replace('Bearer ', '')
const { userId } = jwt.verify(token, process.env.APP_SECRET)
return userId
const token = Authorization.replace("Bearer ", "");
const { userId } = jwt.verify(token, process.env.APP_SECRET);
return userId;
}

throw new AuthError()
throw new AuthError();
}

class AuthError extends Error {
constructor() {
super('Not authorized')
super("Not authorized");
}
}

module.exports = {
getUserId,
AuthError
}
};

0 comments on commit 09b97c3

Please sign in to comment.