From 628c2e834fc42558dc690d2219f297f5e25b25a8 Mon Sep 17 00:00:00 2001 From: Salman Dabbakuti Date: Sat, 20 Nov 2021 18:03:30 +0530 Subject: [PATCH 1/3] added minimal setup without routers, few improvements added minimal setup without routers, few improvements * go to account if token is present in local storage --- app.js | 4 ++-- client/src/Account.js | 5 +---- client/src/App.js | 16 +++++++--------- client/src/Home.js | 2 +- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/app.js b/app.js index 4604401..1459861 100644 --- a/app.js +++ b/app.js @@ -66,7 +66,7 @@ const resolvers = { // TODO: send magic link to user const { _id, firstName, lastName } = userExists; const activationToken = jwt.sign({ _id, firstName, lastName, email }, jwtSecret, { expiresIn: '1 days' }); - emailObj.html = `Welcome, click on below link to signin
Sign in`; + emailObj.html = `Welcome, click on below link to signin
Sign in`; await sendEmailToUser(emailObj); return userExists; } @@ -74,7 +74,7 @@ const resolvers = { const user = await UserModel.create({ email }); const { _id, firstName, lastName, createdAt, updatedAt } = user; const activationToken = jwt.sign({ _id, firstName, lastName, email, createdAt, updatedAt }, jwtSecret, { expiresIn: '1 days' }); - emailObj.html = `Welcome, Confirm your signup by clicking on below link
Confirm`; + emailObj.html = `Welcome, Confirm your signup by clicking on below link
Confirm`; await sendEmailToUser(emailObj); return user; }, diff --git a/client/src/Account.js b/client/src/Account.js index 4af79a6..09d1464 100644 --- a/client/src/Account.js +++ b/client/src/Account.js @@ -17,9 +17,6 @@ export default function Account(props) { }`; useEffect(() => { - const token = props.match.params.token; - localStorage.setItem('TOKEN', token); - client.setHeader('authorization', token ? `Bearer ${token}` : ''); getMyProfile(); }, []); @@ -90,7 +87,7 @@ export default function Account(props) {
-
diff --git a/client/src/App.js b/client/src/App.js index e005d20..1c53d6d 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -1,9 +1,11 @@ -import { BrowserRouter, Route, Switch } from "react-router-dom"; import { GraphQLClient } from 'graphql-request'; import Home from "./Home"; import Account from "./Account"; -const token = localStorage.getItem('TOKEN'); +const tokenParam = new URL(window.location.href).searchParams.get('token'); +const token = tokenParam || localStorage.getItem('TOKEN') || ''; +tokenParam && localStorage.setItem('TOKEN', token); + const client = new GraphQLClient(process.env.REACT_APP_API_URL || 'http://localhost:4000', { headers: { authorization: token ? `Bearer ${token}` : '' @@ -12,12 +14,8 @@ const client = new GraphQLClient(process.env.REACT_APP_API_URL || 'http://localh export default function App() { return ( - - - } /> - } /> -

Not Found

} /> -
-
+ <> + {token ? : } + ); } \ No newline at end of file diff --git a/client/src/Home.js b/client/src/Home.js index 70fd103..fab20e3 100644 --- a/client/src/Home.js +++ b/client/src/Home.js @@ -1,4 +1,3 @@ - import { useState } from 'react' import { gql } from 'graphql-request'; import './index.css' @@ -18,6 +17,7 @@ export default function Home({ client }) { client.request(SEND_MAGICLINK_MUTATION, { email }) .then((data) => { setLoading(false); + setEmail(''); console.log('mutation response:', data); alert('magic link sent to email'); }) From c8de0b327cc289c926f620474bbde199647e994b Mon Sep 17 00:00:00 2001 From: Salman Dabbakuti Date: Sat, 20 Nov 2021 18:16:45 +0530 Subject: [PATCH 2/3] few fixes --- client/package.json | 5 +---- client/src/Account.js | 3 +-- package.json | 1 + 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/client/package.json b/client/package.json index b7e89e0..495c43d 100644 --- a/client/package.json +++ b/client/package.json @@ -1,18 +1,15 @@ { "name": "magiclink-client", - "version": "0.1.0", + "version": "1.0.0", "private": true, "dependencies": { "@testing-library/jest-dom": "^5.14.1", "@testing-library/react": "^11.2.7", "@testing-library/user-event": "^12.8.3", - "graphql": "15.1.0", "graphql-request": "3.5.0", "react": "^17.0.2", "react-dom": "^17.0.2", - "react-router-dom": "5.3.0", "react-scripts": "4.0.3", - "@supabase/supabase-js": "1.21.3", "web-vitals": "^1.1.2" }, "scripts": { diff --git a/client/src/Account.js b/client/src/Account.js index 09d1464..b46d029 100644 --- a/client/src/Account.js +++ b/client/src/Account.js @@ -1,8 +1,7 @@ import { useState, useEffect } from 'react' import { gql } from 'graphql-request'; -export default function Account(props) { - const { client } = props; +export default function Account({ client }) { const [loading, setLoading] = useState(true) const [user, setUser] = useState({ firstName: '', lastName: '', phone: '', email: '' }); diff --git a/package.json b/package.json index 3764ed4..15ca061 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "magiclink-backend", "version": "1.0.0", + "private": true, "description": "Magic Link backend with Nodejs GraphQL (ES6)", "author": "Salman Dabbakuti", "license": "ISC", From f9da40c1d069e9ced20844928fed874e43549c58 Mon Sep 17 00:00:00 2001 From: Salman Dabbakuti Date: Sat, 20 Nov 2021 18:19:35 +0530 Subject: [PATCH 3/3] Update package.json --- client/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/client/package.json b/client/package.json index 495c43d..3fcd541 100644 --- a/client/package.json +++ b/client/package.json @@ -6,6 +6,7 @@ "@testing-library/jest-dom": "^5.14.1", "@testing-library/react": "^11.2.7", "@testing-library/user-event": "^12.8.3", + "graphql": "15.1.0", "graphql-request": "3.5.0", "react": "^17.0.2", "react-dom": "^17.0.2",