Skip to content

Commit

Permalink
Added API to check the the user is already added or not
Browse files Browse the repository at this point in the history
  • Loading branch information
4rjunc committed Mar 10, 2024
1 parent 60f4807 commit de8afe8
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 12 deletions.
8 changes: 8 additions & 0 deletions apis/searchUserID.l2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
GET

https://api.baserow.io/api/database/rows/table/262939/?user_field_names=true&filter__field_1868162__equal=11769

Authorization: Token HgOfMk9hNi5HoAIRHhdlzGgsR0e6WJdG



28 changes: 22 additions & 6 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
import Navbar from "./components/Navbar";
import Form from "./components/Form";
import SearchBar from "./components/SearchBar";
import "./App.css";
import Login from "./components/Login";
import { GoogleOAuthProvider } from "@react-oauth/google";
import { useEffect } from 'react';


function App() {

useEffect(() => {
const handleFocus = () => {
console.log('Focused');
};

const handleBlur = () => {
console.log('Blurred');
};

window.addEventListener('focus', handleFocus);
window.addEventListener('blur', handleBlur);

return () => {
window.removeEventListener('focus', handleFocus);
window.removeEventListener('blur', handleBlur);
};
}, [])


return (
<>
{/* <GoogleOAuthProvider clientId="791186457310-dokutkb0uekegquccairo5fq46qe8aoa.apps.googleusercontent.com"> */}
<Login />
{/* </GoogleOAuthProvider> */};
</>
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ const Form = (props) => {
const [activeTab, setActiveTab] = useState("");
const [user, setUser] = useState();

const userid = props.user
console.log("User in From", props.user, userid)
console.log("User in From", props.user)

//Gets current Tab's URL
async function getCurrentTab() {
Expand Down Expand Up @@ -43,6 +42,7 @@ const Form = (props) => {
getCurrentTab();
//setActiveTab("https://example.com"); //used during development
fetchData();
setUser(props.user)
}, []);

const handleUrlChange = (e) => {
Expand Down
4 changes: 1 addition & 3 deletions src/components/Login.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React, { useState } from "react";
import { useState } from "react";
import Home from "./Home";
import { GoogleLogin } from "@react-oauth/google";
import { jwtDecode } from "jwt-decode";
import { Button } from "@mui/material";
import { login } from "./api";
import Navbar from "./Navbar";
Expand Down
4 changes: 3 additions & 1 deletion src/components/SearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ const SearchBar = () => {

return (
<div>
<Typography>Select the required tags to explore you bookmarks!</Typography>
<Typography style={{ color: "white" }}>
Select the required tags to explore your bookmarks!
</Typography>
<Select
isMulti
options={tagOptions}
Expand Down
19 changes: 19 additions & 0 deletions src/components/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,24 @@ export const addTag = async (tag) => {
// to add userID from Google OAuth
const addUser = async (userID) => {
console.log("userID", userID)
var flag = 0
try {
const response = await axios({
method: "GET",
url: `${API_URL}api/database/rows/table/262939/?user_field_names=true&filter__field_1868162__equal=${userID}`,
headers: {
Authorization: `Token ${import.meta.env.VITE_SECRET}`,
}
});
console.log("Checking User", response , response.status);
if (response.data.count == 0){
flag = 1
}
}catch(error){
console.error("Error while checking user", error)
}

if (flag == 1){
try {
const response = await axios({
method: "POST",
Expand All @@ -98,6 +116,7 @@ const addUser = async (userID) => {
throw error; // re-throw the error to propagate it
}
}
}

export const login = () => {
return new Promise((resolve, reject) => {
Expand Down

0 comments on commit de8afe8

Please sign in to comment.