Browse Source

Merge branch 'master' of https://git.slurm.ch/tomi/u-fit

Tomi Cvetic 5 years ago
parent
commit
fc95f8acc6
5 changed files with 100 additions and 23 deletions
  1. 0 5
      backend/src/resolvers.js
  2. 44 18
      frontend/components/nav.js
  3. 17 0
      frontend/components/user.js
  4. 30 0
      frontend/lib/graphql.js
  5. 9 0
      frontend/pages/user.js

+ 0 - 5
backend/src/resolvers.js

@@ -28,11 +28,6 @@ const Mutation = {
       },
       info
     )
-    const token = jwt.sign({ userId: user.id }, process.env.APP_SECRET)
-    context.response.cookie('token', token, {
-      httpOnly: true,
-      maxAge: 7 * 24 * 3600 * 1000
-    })
     return user
   },
   signup: async (parent, args, ctx, info) => {

+ 44 - 18
frontend/components/nav.js

@@ -1,25 +1,51 @@
 import React from 'react'
 import Link from 'next/link'
 
+import { UserNav } from '../components/user'
+
 const Nav = () => (
-  <nav>
-    <ul>
-      <li>
-        <Link href='/'>
-          <a>Home</a>
-        </Link>
-        <Link href='/archive'>
-          <a>Archive</a>
-        </Link>
-        <Link href='/exercises'>
-          <a>Exercises</a>
-        </Link>
-        <Link href='/polls'>
-          <a>Polls</a>
-        </Link>
-      </li>
-    </ul>
-  </nav>
+  <>
+    <nav>
+      <ul>
+        <li>
+          <Link href='/'>
+            <a>Home</a>
+          </Link>
+        </li>
+        <li>
+          <Link href='/archive'>
+            <a>Archive</a>
+          </Link>
+        </li>
+        <li>
+          <Link href='/exercises'>
+            <a>Exercises</a>
+          </Link>
+        </li>
+        <li>
+          <Link href='/polls'>
+            <a>Polls</a>
+          </Link>
+        </li>
+        <li>
+          <UserNav />
+        </li>
+      </ul>
+    </nav>
+
+    <style jsx>
+      {`
+        ul {
+          padding: 0 0.5em;
+        }
+
+        li {
+          display: inline;
+          margin: 0 0.5em;
+        }
+      `}
+    </style>
+  </>
 )
 
 export default Nav

+ 17 - 0
frontend/components/user.js

@@ -0,0 +1,17 @@
+import { Mutation } from 'react-apollo'
+import Link from 'next/link'
+
+import { USER_LOGIN } from '../lib/graphql'
+
+const UserLoginForm = props => <p>Login Form</p>
+
+const UserNav = props => (
+  <Link href='user'>
+    <a>test</a>
+  </Link>
+)
+
+const User = props => <a />
+
+export { UserNav }
+export default User

+ 30 - 0
frontend/lib/graphql.js

@@ -0,0 +1,30 @@
+import { mutation } from 'react-apollo'
+import gql from 'graphql-tag'
+
+const USER_LOGIN = gql`
+  mutation USER_LOGIN($email: String!, $password: String!) {
+    login(email: $email, password: $password) {
+      id
+      email
+      name
+    }
+  }
+`
+
+const USER_LOGOUT = gql`
+  mutation USER_LOGOUT {
+    logout {
+      id
+    }
+  }
+`
+
+const USER_SIGNUP = gql`
+  mutation USER_SIGNUP($email: String!, $password: String!, $name: String!) {
+    signup(email: $email, password: $password, name: $name) {
+      id
+    }
+  }
+`
+
+export { USER_LOGIN, USER_LOGOUT, USER_SIGNUP }

+ 9 - 0
frontend/pages/user.js

@@ -0,0 +1,9 @@
+import User from '../components/user'
+
+const UserPage = props => (
+  <section>
+    <p>This is the user page.</p>
+  </section>
+)
+
+export default UserPage