Skip to content

Commit

Permalink
Merge pull request #165 from Dindb-dong/feat/144/MyPage
Browse files Browse the repository at this point in the history
#116: render Tab Navigator depend on UserRole
  • Loading branch information
Dindb-dong authored Nov 27, 2024
2 parents 8e96b65 + 4d5def8 commit 13b06d3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
5 changes: 3 additions & 2 deletions src/common/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export async function getNickname() {
export function setNickname(nickname) {
const sanitizedNickname = nickname || ""; // 기본값 설정
setSecureValue(nicknameKeyName, sanitizedNickname);
console.log('User Nickname saved successfully');
}

export function removeNickname() {
Expand Down Expand Up @@ -90,10 +91,10 @@ export function setUserRole(role) {

Keychain.setInternetCredentials(userRole, username, password)
.then(() => {
console.log("Market UUID saved successfully");
console.log("userRole saved successfully");
})
.catch(error => {
console.error("Failed to save Market UUID:", error);
console.error("Failed to save userRole:", error);
});
}

Expand Down
26 changes: 22 additions & 4 deletions src/components/Auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import {
setAccessToken,
setNickname,
setRefreshToken,
setUserRole
setUserRole,
getUserRole,
setMarketUUID
} from '../../common/storage';
import { LoginContext, useUser } from '../../common/Context';

Expand Down Expand Up @@ -92,6 +94,8 @@ export const processLoginResponse2 = async ( // 회원가입시에 사용하는
if (response?.status === 200) {
const user_role = response.data.role;
setUserRole(user_role);
const role = await getUserRole();
console.log('processLogin2에서 유저롤 설정 완료', role);
}
} catch (err) {
console.log(err);
Expand Down Expand Up @@ -125,20 +129,34 @@ export async function processLoginResponse( // 통상 로그인시 호출 함수
setAccessToken(accessToken);
setRefreshToken(refreshToken);
console.log({ accessToken }, ',', { refreshToken });
setLogin(true);
try { // 유저 롤 설정 // 근데 이걸 꼭 여기서 할 필요가 있나? 혹시 모르니 만들어두긴 함
try { // 유저롤 설정
const response = await request.get(`/api/user`, {}, headers)
if (response?.status === 200) {
const user_role = response.data.role;
setUserRole(user_role);
const role = await getUserRole();
console.log('processLogin에서 유저롤 설정 완료', role);
setLogin(true);
if (role === 'reformer') { // 리폼러인 경우, marketUUID 저장
try {
const response = await request.get(`/api/market`, {}, headers)
if (response.status && response.status === 200) {
setMarketUUID(response.data[0].market_uuid);
} else {
console.log(response);
}
} catch (error) {
console.error(error);
}

}
}
} catch (err) {
console.log(err);
console.log('유저롤 설정 오류');
}
navigate(); // 인자로 전달받은 네비게이팅 수행
console.log('로그인 성공');

} else if (response.status === 400) {
Alert.alert('비밀번호가 틀렸습니다.');
} else if (response.status === 404) {
Expand Down
8 changes: 0 additions & 8 deletions src/components/Auth/Reformer/ReformFormCareer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -966,14 +966,6 @@ export default function ReformCareer({ fix, form, setForm }: ReformProps) {
}}
style={{ width: '90%', alignSelf: 'center', marginBottom: 10 }}
/>
<BottomButton
value="role"
pressed={false}
onPress={() => {

}}
style={{ width: '90%', alignSelf: 'center', marginBottom: 10 }}
/>
</View>}
</View>
{careerIndex >= 0 && (
Expand Down
7 changes: 6 additions & 1 deletion src/components/Auth/Reformer/ReformerMyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import DetailScreenHeader from '../../../components/Home/components/DetailScreen
import { PhotoType } from '../../../hooks/useImagePicker.ts';
import Request from '../../../common/requests.js';
import { MypageStackProps } from '../../../pages/MyPage.tsx';
import { getAccessToken, getRefreshToken, getUserRole, removeAccessToken, removeRefreshToken, setUserRole } from '../../../common/storage.js';
import { getAccessToken, getMarketUUID, getNickname, getRefreshToken, getUserRole, removeAccessToken, removeRefreshToken, setNickname, setUserRole } from '../../../common/storage.js';
import { CommonActions, useFocusEffect } from '@react-navigation/native';
import { Title20B } from '../../../styles/GlobalText.tsx';
import DeleteModal from '../DeleteModal.tsx';
Expand Down Expand Up @@ -118,6 +118,7 @@ export const ReformerMyPageScreen = ({ navigation, route }: MypageStackProps) =>

const request = Request();
const { isLogin, setLogin } = useContext(LoginContext);
const [market_uuid, setMarket_uuid] = useState<any>('');
const [reformerInfo, setReformerInfo] = useState({
nickname: route.params?.nickname || '',
backgroundphoto:
Expand Down Expand Up @@ -169,6 +170,9 @@ export const ReformerMyPageScreen = ({ navigation, route }: MypageStackProps) =>
'나는야 업씨러 이하늘 환경을 사랑하지요 눈누난나',
role: 'reformer',
});
setNickname(response.data.nickname);
const UUID = await getMarketUUID();
setMarket_uuid(UUID);
return response.data;
} else {
console.log('Failed to fetch user data:', response);
Expand Down Expand Up @@ -365,6 +369,7 @@ export const ReformerMyPageScreen = ({ navigation, route }: MypageStackProps) =>
</Tabs.Tab>
<Tabs.Tab name="서비스" key="service">
<View>

{/*<TouchableOpacity
style={styles.saveButton}
onPress={() => navigation.navigate('TempStorage')}>
Expand Down
7 changes: 0 additions & 7 deletions src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import { stylesList } from '../components/Home/HomeMain';
import SearchPage from './SearchPage';
import { ServiceDetailOption } from '../components/Home/Market/Service';
import ReportPage from './ReportPage';
import { getUserRole } from '../common/storage';

export type HomeStackParams = {
Home: { searchTerm?: string };
Expand Down Expand Up @@ -204,11 +203,6 @@ const HomeMainScreen = ({
const [selectedStylesList, setSelectedStylesList] =
useState<string[]>(stylesList);

const checkRole = async () => {
const role = await getUserRole();
console.log('유저롤:', role);
};

return (
<Fragment>
<SafeAreaView style={{ flex: 0, backgroundColor: PURPLE }} />
Expand All @@ -228,7 +222,6 @@ const HomeMainScreen = ({
</View>
{selectedTab === 'Goods' && (
<View>
<Button onPress={checkRole}></Button>
<Service
selectedStylesList={selectedStylesList}
selectedFilterOption={selectedFilterOption}
Expand Down

0 comments on commit 13b06d3

Please sign in to comment.