Skip to content

Commit

Permalink
Merge branch 'main' into feat/RankingUI
Browse files Browse the repository at this point in the history
  • Loading branch information
glowisn authored Feb 29, 2024
2 parents 4e37146 + 1d5714d commit 1df858c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 53 deletions.
34 changes: 17 additions & 17 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ jobs:
- name: Client lint
run: docker compose run client npm run lint

cd:
runs-on: ubuntu-latest
needs: ci
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
# ssh to server and run commands
steps:
- name: SSH and Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd ~/project/develop &&
git checkout main &&
git pull origin &&
docker compose up --build -d
# cd:
# runs-on: ubuntu-latest
# needs: ci
# if: github.event_name == 'push' && github.ref == 'refs/heads/main'
# # ssh to server and run commands
# steps:
# - name: SSH and Deploy
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.SERVER_HOST }}
# username: ${{ secrets.SERVER_USER }}
# key: ${{ secrets.SSH_PRIVATE_KEY }}
# script: |
# cd ~/project/develop &&
# git checkout main &&
# git pull origin &&
# docker compose up --build -d
14 changes: 3 additions & 11 deletions client/src/contexts/AuthProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
ReactNode,
createContext,
useEffect,
useState,
Dispatch,
SetStateAction,
} from 'react';
import { ReactNode, createContext, useEffect, useState } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import { UserSession } from '../types/UserSessionType';
import { logout } from '../apis/logout';
Expand All @@ -15,7 +8,6 @@ import { useLocalStorage } from './useLocalStorage';
export interface AuthContextType {
user: UserSession | null;
isLoading: boolean;
setIsLoading: Dispatch<SetStateAction<boolean>>;
}

export interface AuthUpdateType {
Expand Down Expand Up @@ -43,12 +35,12 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {

const onLogout = async () => {
await logout();
// setUser(null);
removeItem('userInfo');
navigate('/');
};

useEffect(() => {
setIsLoading(true);
getSession().then((data) => {
if (data) {
setUser(data);
Expand All @@ -61,7 +53,7 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
}, [location]);

return (
<AuthContext.Provider value={{ user, isLoading, setIsLoading }}>
<AuthContext.Provider value={{ user, isLoading }}>
<AuthUpdateContext.Provider value={{ onLogout }}>
{children}
</AuthUpdateContext.Provider>
Expand Down
54 changes: 29 additions & 25 deletions client/src/pages/UserBasedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,38 @@ export default function UserBasedRoute({
}: {
children: JSX.Element;
}) {
const { user, isLoading, setIsLoading } = useAuthContext();
const { user, isLoading } = useAuthContext();
const location = useLocation();

if (!isLoading) {
setIsLoading(true);
if (user) {
if (user.participatingRoomCode) {
if (location.pathname !== `/room/${user.participatingRoomCode}`) {
return (
<Navigate
to={`/room/${user.participatingRoomCode}`}
state={{
isHost: user.isHost,
roomCode: user.participatingRoomCode,
}}
replace
/>
);
}
} else {
if (location.pathname !== '/lobby') {
return <Navigate to="/lobby" replace />;
}
}
} else {
if (location.pathname !== '/' && location.pathname !== '/home') {
return <Navigate to="/" replace />;
}
const isNotLoggedIn =
!user && location.pathname !== '/' && location.pathname !== '/home';
const isNotParticipatingRoom =
user && !user.participatingRoomCode && location.pathname !== '/lobby';
const isParticipatingRoom =
user &&
user.participatingRoomCode &&
location.pathname !== `/room/${user.participatingRoomCode}`;

if (isNotLoggedIn) {
return <Navigate to="/" replace />;
}

if (isNotParticipatingRoom) {
return <Navigate to="/lobby" replace />;
}

if (isParticipatingRoom) {
return (
<Navigate
to={`/room/${user.participatingRoomCode}`}
state={{
isHost: user.isHost,
roomCode: user.participatingRoomCode,
}}
replace
/>
);
}
}

Expand Down

0 comments on commit 1df858c

Please sign in to comment.