diff --git a/services/auth/resolvers/authResolvers.ts b/services/auth/resolvers/authResolvers.ts index 45d9a3b..bce6741 100644 --- a/services/auth/resolvers/authResolvers.ts +++ b/services/auth/resolvers/authResolvers.ts @@ -1,36 +1,26 @@ -function loginUserResolver() { - return { - Subscription: { - loginUser: { - subscribe: async ({ email, password }: { email: string; password: string; }, { pubsub }: { pubsub }: { EventEmitter }) => { - loginUser({ email, password }); - return pubsub.asyncIterator('LOGIN_SUCCESS' || 'LOGIN_FAILURE'); - } - } - } - }; + +type userLoginInput = { + email: String! + password: String! } -function logoutUserResolver() { - return { - Subscription: { - logoutUser: { - subscribe: async ({ email }: { email: string }, { pubsub }: { pubsub }: { EventEmitter }) => { - logoutUser({ email }); - return pubsub.asyncIterator('LOGOUT_SUCCESS' || 'LOGOUT_FAILURE'); - } - } - } - }; -} -function createUserResolver() { - return { - Mutation: { - createUser: async ({ email, password }: { email: string; password: string; }) => { - const user = await createUser({ email, password }); - return user ? "USER_CREATED_SUCCESS" : "USER_CREATION_FAILED"; +const resolvers = { + Mutation: { + login: async (_parent, { input: input }, context) => { + const { email, password } = input; + // Db connection and authentication logic here + const user = await context.db.users.findOne({ email }); + if (!user || user.password !== password || !user.email) { + return { userLoginSuccessStatus: false }; + else if (user && user.password === password && user.email) { + return { userLoginSuccessStatus: true }; } - } - }; -} \ No newline at end of file + else { + return { userLoginSuccessStatus: false }; + console.log("User not found or unknown error"); + } + }, + + } + } \ No newline at end of file diff --git a/services/auth/schema/auth.graphql b/services/auth/schema/auth.graphql index e24fc91..48cfcf2 100644 --- a/services/auth/schema/auth.graphql +++ b/services/auth/schema/auth.graphql @@ -1,20 +1,30 @@ -type Login { +type userLogin { email: String! password: String! } -type LoginResponse { - loginStatus: Boolean! +type userLoginResponse { + userLoginSuccessStatus: Boolean! } -type Subscription { - login: Login! - }, - required: ["email", "password"] - -subscription login($email: String!, $password: String!) { - login(email: $email, password: $password) { - id - email - loginStatus +type userLogout { + email: String! } -} \ No newline at end of file +type userLogoutResponse { + userLoggedOutSuccessStatus: Boolean! + } +type CreateUser { + firstName: String! + lastName: String! + email: String! + password: String! + dateOfBirth: String! + } +type CreateUserResponse { + userCreatedStatus: Boolean! + } + +type Mutation { + login(input: userLogin!): userLoginResponse! + logout(input: userLogout!): user LogoutResponse! + createUser(input: CreateUser!): CreateUserResponse! + } \ No newline at end of file