Skip to content

Commit

Permalink
Merge branch 'dev' into feat/#60-review
Browse files Browse the repository at this point in the history
  • Loading branch information
Zero-1016 committed Oct 9, 2024
2 parents cb3f3aa + 452a402 commit 0455968
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 27 deletions.
35 changes: 27 additions & 8 deletions app/(beforeLogin)/oauth2/authorization/login.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
import styled from '@emotion/native';
import { useRoute } from '@react-navigation/core';
import React, { useEffect } from 'react';
import { useRouter } from 'expo-router';
import React, { useEffect, useState } from 'react';
import { ActivityIndicator } from 'react-native';

import { useSession } from '@/store';
import { flexDirectionColumnItemsCenter } from '@/styles/common';
import { setHeader } from '@/utils';

function Login() {
const [loading, setLoading] = useState(true);
const route = useRoute();
const router = useRouter();
const { signIn } = useSession();

const { token, refresh } = route.params as { token?: string; refresh?: string };

useEffect(() => {
if (typeof token === 'string' && typeof refresh === 'string') {
setHeader('Authorization', `Bearer ${token}`);
signIn(refresh);
}
// ts-expect-error signIn을 넣을 경우 무한 재 렌더링을 하게 됩니다.
}, [refresh, token]);
useEffect(
function setToken() {
if (typeof token === 'string' && typeof refresh === 'string') {
setHeader('Authorization', `Bearer ${token}`);
signIn(refresh);
}

setLoading(false);
// ts-expect-error signIn을 넣을 경우 무한 재 렌더링을 하게 됩니다.
},
[refresh, token]
);

useEffect(
function isNotLoadRedirect() {
if (!loading) {
router.replace('/');
}
},
[loading, router]
);

return (
<S.Container>
Expand All @@ -32,6 +50,7 @@ function Login() {

const S = {
Container: styled.SafeAreaView`
${flexDirectionColumnItemsCenter};
flex: 1;
`,
};
Expand Down
13 changes: 8 additions & 5 deletions app/(beforeLogin)/sign-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ import { getSize } from '@/utils';
function SignIn() {
const { signIn, refreshToken } = useSession();

useEffect(() => {
if (refreshToken) {
signIn();
}
}, [refreshToken, signIn]);
useEffect(
function ifHasRefreshTokenGoToMain() {
if (refreshToken) {
signIn(refreshToken);
}
},
[refreshToken, signIn]
);

return (
<S.LoginWrapper>
Expand Down
6 changes: 0 additions & 6 deletions src/components/home/BusinessCard/BusinessCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ const SkeletonMeta: Meta<typeof BusinessCard> = {
},
description: '스크린에 보이는지 여부를 입력해주세요',
},
onboarding: {
control: {
type: 'boolean',
},
description: '온보딩 화면인지 여부를 입력해주세요',
},
},
parameters: {
layout: 'centered',
Expand Down
10 changes: 2 additions & 8 deletions src/store/useSession.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { useRouter } from 'expo-router';
import { createContext, type PropsWithChildren, useContext } from 'react';

import { STORAGE_KEYS } from '@/constants';
import { useStorageState } from '@/hooks/useStorageState';
import { useOnboarding } from '@/store/useOnboarding';

const AuthContext = createContext<{
signIn: (refreshToken?: string | null) => void;
signIn: (refreshToken: string) => void;
signOut: () => void;
refreshToken?: string | null;
isLoading: boolean;
Expand All @@ -33,18 +32,13 @@ export function useSession() {

export function SessionProvider({ children }: PropsWithChildren) {
const [[isLoading, refreshToken], setSession] = useStorageState(STORAGE_KEYS.SESSION);
const router = useRouter();
const { resetOnBoarding } = useOnboarding();

return (
<AuthContext.Provider
value={{
signIn: (refreshToken = null) => {
if (refreshToken !== null) {
router.push('/');
}
signIn: (refreshToken: string) => {
setSession(refreshToken);
router.push('/');
},
signOut: () => {
setSession(null);
Expand Down

0 comments on commit 0455968

Please sign in to comment.