From 9eebcab5e9a075166ac284b24c7e736ffd304b56 Mon Sep 17 00:00:00 2001 From: Apoorva Mohite Date: Tue, 27 Feb 2024 23:16:48 -0800 Subject: [PATCH] Moved getToken to App.js --- wildfirestorage-spring/app/src/App.js | 25 ++++++++++++++++++ .../app/src/components/landing/landing.jsx | 26 ------------------- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/wildfirestorage-spring/app/src/App.js b/wildfirestorage-spring/app/src/App.js index 8f5c289..59d7c57 100644 --- a/wildfirestorage-spring/app/src/App.js +++ b/wildfirestorage-spring/app/src/App.js @@ -4,8 +4,33 @@ import { BrowserRouter, Routes, Route } from "react-router-dom"; import Landing from './components/landing/landing'; import Token from './components/token/token'; import Forbidden from './components/forbidden/forbidden'; +import { useDispatch } from 'react-redux'; +import { setOpaqueToken } from './redux/userSlice'; +import { useEffect } from 'react'; function App() { + const dispatch = useDispatch(); + + const getToken = async () => { + const response = await fetch("/api/oauth/token", { + method: "GET", + headers: { + "Content-Type": "application/json", + "Accept": "text/plain, application/json", + }, + credentials: "include", + redirect: "follow", + }); + if (response.redirected) { + document.location = response.url; + } + let d = await response.text(); + dispatch(setOpaqueToken(d)); + console.log("tokennnn", d) + } + useEffect(() => { + getToken(); + }, []) return ( diff --git a/wildfirestorage-spring/app/src/components/landing/landing.jsx b/wildfirestorage-spring/app/src/components/landing/landing.jsx index a4236eb..be63977 100644 --- a/wildfirestorage-spring/app/src/components/landing/landing.jsx +++ b/wildfirestorage-spring/app/src/components/landing/landing.jsx @@ -1,11 +1,7 @@ import { Link, useNavigate } from "react-router-dom"; -import { useDispatch } from 'react-redux'; -import { setOpaqueToken } from '../../redux/userSlice'; -import { useEffect } from 'react'; const Landing = () => { const navigate = useNavigate(); - const dispatch = useDispatch(); const goToSearch = async () => { const response = await fetch("/api/oauth/checkAccess", { @@ -26,28 +22,6 @@ const Landing = () => { } } - const getToken = async () => { - const response = await fetch("/api/oauth/token", { - method: "GET", - headers: { - "Content-Type": "application/json", - "Accept": "text/plain, application/json", - }, - credentials: "include", - redirect: "follow", - }); - if (response.redirected) { - document.location = response.url; - } - let d = await response.text(); - dispatch(setOpaqueToken(d)); - console.log("tokennnn", d) - } - - useEffect(() => { - getToken(); - }, []) - return (