Skip to content

Commit

Permalink
Moved getToken to App.js
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorvamohite committed Feb 28, 2024
1 parent b31c96a commit 9eebcab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
25 changes: 25 additions & 0 deletions wildfirestorage-spring/app/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<BrowserRouter>
Expand Down
26 changes: 0 additions & 26 deletions wildfirestorage-spring/app/src/components/landing/landing.jsx
Original file line number Diff line number Diff line change
@@ -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", {
Expand All @@ -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 (
<div className="flex place-content-center">
<div className="h-screen flex flex-col place-content-center w-9/12">
Expand Down

0 comments on commit 9eebcab

Please sign in to comment.