Skip to content

Commit

Permalink
Refactor gateway url and obtaining user
Browse files Browse the repository at this point in the history
  • Loading branch information
yhtMinceraft1010X committed Oct 8, 2023
1 parent 76b393f commit cde0be3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion frontend/src/firebase-client/gateway-address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ const gatewayAddress = (process.env.NODE_ENV === "development")
? "http://localhost:4000/"
: "http://gateway:4000/";

export const userApiPathAddress = gatewayAddress + "api/user-service/"
export const userApiPathAddress = gatewayAddress + "api/user-service/";
export const questionApiPathAddress = gatewayAddress + "api/question-service/";
10 changes: 6 additions & 4 deletions frontend/src/pages/questions/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { useQuestion } from "@/hooks/useQuestion";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { TypographyBody } from "@/components/ui/typography";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";
import {useContext, useEffect, useState} from "react";
import { Question } from "../../../types/QuestionTypes";
import {auth} from "@/firebase-client/firebase_config";
import {questionApiPathAddress} from "@/firebase-client/gateway-address";
import {AuthContext} from "@/contexts/AuthContext";

export default function Room() {
const router = useRouter();
Expand All @@ -15,13 +17,13 @@ export default function Room() {
const [loading, setLoading] = useState(true);
const [answer, setAnswer] = useState("");

const { currentUser, authIsReady } = useContext(AuthContext);

useEffect(() => {
if (!router.isReady) return;
const fetchQuestion = async () => {
const currentUser = auth.currentUser;
if (currentUser) {
const idToken = await currentUser.getIdToken(true);
const url = `http://localhost:4000/api/question-service/question/${questionTitle}`;
const url = `${questionApiPathAddress}question/${questionTitle}`;

console.log(url);

Expand Down
9 changes: 5 additions & 4 deletions frontend/src/pages/questions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@ import {
} from "@/components/ui/typography";
import Link from "next/link";
import { Button } from "@/components/ui/button";
import { useEffect, useState } from "react";
import {useContext, useEffect, useState} from "react";
import DifficultySelector from "@/components/common/difficulty-selector";
import { columns, Question } from "@/components/questions/columns";
import { DataTable } from "@/components/questions/data-table";
import { Difficulty } from "../../../types/QuestionTypes";
import {auth} from "@/firebase-client/firebase_config";
import {questionApiPathAddress} from "@/firebase-client/gateway-address";
import {AuthContext} from "@/contexts/AuthContext";

export default function Questions() {
const [difficulty, setDifficulty] = useState<Difficulty>("medium");

const [questions, setQuestions] = useState<Question[]>([]);
const currentUser = auth.currentUser;
const { currentUser, authIsReady } = useContext(AuthContext);


useEffect(() => {
if (currentUser) {
const url = "http://localhost:4000/api/question-service/list";
const url = `${questionApiPathAddress}list`;
currentUser.getIdToken(true).then((idToken) => {
fetch(url, {
method: "GET",
Expand Down

0 comments on commit cde0be3

Please sign in to comment.