Commit 0d8bc28d authored by 우지원's avatar 우지원
Browse files

0809

parent 0e228dad
...@@ -2,7 +2,7 @@ import { Link } from 'react-router-dom' ...@@ -2,7 +2,7 @@ import { Link } from 'react-router-dom'
import { handleLogout } from '../context/auth' import { handleLogout } from '../context/auth'
const Header = () => { const Header = () => {
const id = localStorage.getItem('user'); const id = sessionStorage.getItem('user');
return ( return (
<div> <div>
<form <form
......
...@@ -3,7 +3,7 @@ import { Redirect } from "react-router-dom"; ...@@ -3,7 +3,7 @@ import { Redirect } from "react-router-dom";
import roomApi from "../../apis/room.api"; import roomApi from "../../apis/room.api";
import catchErrors from "../../context/catchError"; import catchErrors from "../../context/catchError";
const id = localStorage.getItem('user'); const id = sessionStorage.getItem('user');
const INIT_ROOM = { const INIT_ROOM = {
name: '', name: '',
profileimg: '', profileimg: '',
......
...@@ -3,7 +3,7 @@ import { useState, useEffect } from "react"; ...@@ -3,7 +3,7 @@ import { useState, useEffect } from "react";
import userApi from "../../apis/user.api"; import userApi from "../../apis/user.api";
import catchErrors from "../../context/catchError"; import catchErrors from "../../context/catchError";
const userprofile = localStorage.getItem("user"); const userprofile = sessionStorage.getItem("user");
const INIT_USER = { const INIT_USER = {
id: userprofile, id: userprofile,
email: "", email: "",
......
...@@ -3,7 +3,7 @@ import { Redirect } from "react-router-dom"; ...@@ -3,7 +3,7 @@ import { Redirect } from "react-router-dom";
import roomApi from "../../apis/room.api"; import roomApi from "../../apis/room.api";
import catchErrors from "../../context/catchError"; import catchErrors from "../../context/catchError";
const id = localStorage.getItem("user"); const id = sessionStorage.getItem("user");
const JoinRoom = () => { const JoinRoom = () => {
const [roomId, setRoomId] = useState(""); const [roomId, setRoomId] = useState("");
......
...@@ -4,7 +4,7 @@ import roomApi from "../../apis/room.api"; ...@@ -4,7 +4,7 @@ import roomApi from "../../apis/room.api";
import userApi from "../../apis/user.api"; import userApi from "../../apis/user.api";
import catchErrors from "../../context/catchError"; import catchErrors from "../../context/catchError";
const id = localStorage.getItem("user"); const id = sessionStorage.getItem("user");
const INIT_ROOM = { const INIT_ROOM = {
roomId: "", roomId: "",
name: "", name: "",
......
...@@ -13,7 +13,7 @@ const KakaoShareButton = (porps) => { ...@@ -13,7 +13,7 @@ const KakaoShareButton = (porps) => {
const [inviteperson, setProfile] = useState(INIT_invite); const [inviteperson, setProfile] = useState(INIT_invite);
const [error, setError] = useState(""); const [error, setError] = useState("");
const { roomId } = useParams(); const { roomId } = useParams();
const invitepersonId = localStorage.getItem("user"); const invitepersonId = sessionStorage.getItem("user");
async function getProfile(userID) { async function getProfile(userID) {
try { try {
......
...@@ -2,7 +2,7 @@ import userApi from "../../apis/user.api"; ...@@ -2,7 +2,7 @@ import userApi from "../../apis/user.api";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import catchErrors from "../../context/catchError"; import catchErrors from "../../context/catchError";
const userprofile = localStorage.getItem("user"); const userprofile = sessionStorage.getItem("user");
const INIT_PROFILE = { const INIT_PROFILE = {
name: "", name: "",
email: "a", email: "a",
......
...@@ -3,7 +3,7 @@ import React, { useEffect, useState } from "react"; ...@@ -3,7 +3,7 @@ import React, { useEffect, useState } from "react";
import userApi from "../../apis/user.api"; import userApi from "../../apis/user.api";
import catchErrors from "../../context/catchError"; import catchErrors from "../../context/catchError";
const userprofile = localStorage.getItem("user"); const userprofile = sessionStorage.getItem("user");
const INIT_PROFILE = { const INIT_PROFILE = {
id: userprofile, id: userprofile,
name:"", name:"",
......
...@@ -3,7 +3,7 @@ import { useState, useEffect } from "react"; ...@@ -3,7 +3,7 @@ import { useState, useEffect } from "react";
import userApi from "../../apis/user.api"; import userApi from "../../apis/user.api";
import catchErrors from "../../context/catchError"; import catchErrors from "../../context/catchError";
const userprofile = localStorage.getItem("user"); const userprofile = sessionStorage.getItem("user");
const INIT_PROFILE = { const INIT_PROFILE = {
img:"", img:"",
}; };
......
...@@ -15,7 +15,7 @@ const ChannelList = () => { ...@@ -15,7 +15,7 @@ const ChannelList = () => {
const { roomId } = useParams(); const { roomId } = useParams();
const [error, setError] = useState(""); const [error, setError] = useState("");
const [channel, setChannel] = useState([INIT_CHANNEL]); const [channel, setChannel] = useState([INIT_CHANNEL]);
const id = localStorage.getItem('user'); const id = sessionStorage.getItem('user');
async function getChannel(roomId) { async function getChannel(roomId) {
try { try {
......
...@@ -9,7 +9,7 @@ const ChannelSingle = (props) => { ...@@ -9,7 +9,7 @@ const ChannelSingle = (props) => {
const [success, setSuccess] = useState(false); const [success, setSuccess] = useState(false);
const [roomName, setRoomName] = useState(''); const [roomName, setRoomName] = useState('');
const { roomId, channelId } = useParams(); const { roomId, channelId } = useParams();
const userId = localStorage.getItem('user') const userId = sessionStorage.getItem('user')
async function joinChannel(e) { async function joinChannel(e) {
......
...@@ -5,6 +5,7 @@ import RoomApi from "../../apis/room.api"; ...@@ -5,6 +5,7 @@ import RoomApi from "../../apis/room.api";
import catchErrors from "../../context/catchError"; import catchErrors from "../../context/catchError";
import KakaoShareButton from "../KakaoShareButton"; import KakaoShareButton from "../KakaoShareButton";
import Roomnamechange from "./Roomnamechange"; import Roomnamechange from "./Roomnamechange";
import UserApi from "../../apis/user.api";
const INIT_ROOM = { const INIT_ROOM = {
name: "", name: "",
...@@ -20,7 +21,7 @@ const RightHamburger = () => { ...@@ -20,7 +21,7 @@ const RightHamburger = () => {
const [room, setRoom] = useState([INIT_ROOM]); const [room, setRoom] = useState([INIT_ROOM]);
const { roomId } = useParams(); const { roomId } = useParams();
const [error, setError] = useState(""); const [error, setError] = useState("");
const id = localStorage.getItem("user"); const id = sessionStorage.getItem("user");
async function getRoom(roomId) { async function getRoom(roomId) {
try { try {
...@@ -40,7 +41,7 @@ const RightHamburger = () => { ...@@ -40,7 +41,7 @@ const RightHamburger = () => {
async function exitRoom() { async function exitRoom() {
console.log("id, roomid정보", id, roomId); console.log("id, roomid정보", id, roomId);
try { try {
const data = await RoomApi.exitRoom({ id, roomId }); await RoomApi.exitRoom({ id, roomId });
} catch (error) { } catch (error) {
catchErrors(error, setError); catchErrors(error, setError);
} }
...@@ -66,6 +67,34 @@ const RightHamburger = () => { ...@@ -66,6 +67,34 @@ const RightHamburger = () => {
} }
} }
async function exitChannel() {
try {
const data = await UserApi.getUser(id);
const A = doubleJoinCheck(data.name)
if (A) {
await RoomApi.doubleJoin({ roomId: roomId, index1: A.index1, index2: A.index2, joinChName: A.joinChName })
}
} catch (error) {
catchErrors(error, setError);
}
}
function doubleJoinCheck(e) {
for (const index in channel) {
for (const el in channel[index].joinUser) {
if (channel[index].joinUser[el] === e) {
const doublejoinCh = channel[index].channelName
const A = {
index1: index,
index2: el,
joinChName: doublejoinCh,
}
return A
}
}
}
}
// console.log(channel) // console.log(channel)
useEffect(() => { useEffect(() => {
...@@ -288,7 +317,7 @@ const RightHamburger = () => { ...@@ -288,7 +317,7 @@ const RightHamburger = () => {
> >
<button <button
type="button" type="button"
onClick={exitRoom} onClick={exitRoom, exitChannel}
className="btn btn-primary" className="btn btn-primary"
data-bs-dismiss="modal" data-bs-dismiss="modal"
> >
......
import axios from 'axios' import axios from 'axios'
export function handleLogin(userId) { export function handleLogin(userId) {
localStorage.setItem("user", userId) sessionStorage.setItem("user", userId)
} }
export async function handleLogout() { export async function handleLogout() {
alert("로그아웃되었습니다.") alert("로그아웃되었습니다.")
localStorage.removeItem("user") sessionStorage.removeItem("user")
await axios.get('/api/auth/logout') await axios.get('/api/auth/logout')
window.location.href='/' window.location.href='/'
} }
export function isAuthenticated() { export function isAuthenticated() {
const userId = localStorage.getItem('loginStatus') const userId = sessionStorage.getItem('loginStatus')
if (userId) { if (userId) {
return userId return userId
}else{ }else{
......
...@@ -36,7 +36,7 @@ const AuthProvider = ({ children }) => { ...@@ -36,7 +36,7 @@ const AuthProvider = ({ children }) => {
setError(""); setError("");
setLoading(true); setLoading(true);
const user = await authApi.login(email, password); const user = await authApi.login(email, password);
localStorage.setItem(config.loginUser, JSON.stringify(user)); sessionStorage.setItem(config.loginUser, JSON.stringify(user));
setUser(user); setUser(user);
return true; return true;
...@@ -53,7 +53,7 @@ const AuthProvider = ({ children }) => { ...@@ -53,7 +53,7 @@ const AuthProvider = ({ children }) => {
setError(""); setError("");
setUser(null); setUser(null);
alert("로그아웃되었습니다."); alert("로그아웃되었습니다.");
localStorage.removeItem(config.loginUser); sessionStorage.removeItem(config.loginUser);
setLoading(true); setLoading(true);
await axios.get(`${baseUrl}/api/auth/logout`); await axios.get(`${baseUrl}/api/auth/logout`);
} catch (error) { } catch (error) {
......
import Header from "../components/Header"; import Header from "../components/Header";
const InvitePage = () => { const InvitePage = () => {
const usercheck = localStorage.getItem("user"); const usercheck = sessionStorage.getItem("user");
function goInvitedroom() { function goInvitedroom() {
let check1= null; let check1= null;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment