Skip to content

Commit

Permalink
refactor: migrate authentication using Clerk (#15)
Browse files Browse the repository at this point in the history
https://clerk.com/docs/custom-flows/oauth-connections

Currently support `Github`, `Google`, and `Apple`.
  • Loading branch information
hyochan authored Sep 19, 2024
1 parent 4625152 commit a763aae
Show file tree
Hide file tree
Showing 61 changed files with 2,649 additions and 1,180 deletions.
6 changes: 2 additions & 4 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
DATABASE_URL=
supabaseUrl=
supabaseAnonKey=
googleClientIdAndroid=
googleClientIdIOS=
googleClientIdWeb=
expoProjectId=
expoProjectId=
EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY=
2 changes: 1 addition & 1 deletion .github/workflows/deploy-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
env:
supabaseUrl: ${{ secrets.supabaseUrl }}
supabaseAnonKey: ${{ secrets.supabaseAnonKey }}
googleClientIdWeb: ${{ secrets.googleClientIdWeb }}
EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY: ${{ secrets.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY }}
expoProjectId: ${{ secrets.expoProjectId }}

# Meta tags are not updatable from Expo SDK 49 so add below step
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
env:
supabaseUrl: ${{ secrets.supabaseUrl }}
supabaseAnonKey: ${{ secrets.supabaseAnonKey }}
googleClientIdWeb: ${{ secrets.googleClientIdWeb }}
EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY: ${{ secrets.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY }}
expoProjectId: ${{ secrets.expoProjectId }}

# Meta tags are not updatable from Expo SDK 49 so add below step
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@
"Pressable",
"Pretendard",
"svgs"
]
],
"typescript.tsdk": "node_modules/typescript/lib"
}
7 changes: 2 additions & 5 deletions app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if (process.env.STAGE) {
}

const DEEP_LINK_URL = '[firebaseAppId].web.app';
const buildNumber = 8;
const buildNumber = 12;

export default ({config}: ConfigContext): ExpoConfig => ({
...config,
Expand All @@ -46,6 +46,7 @@ export default ({config}: ConfigContext): ExpoConfig => ({
],
// @ts-ignore
withAndroidLocalizedName,
'expo-secure-store',
'expo-router',
'expo-localization',
[
Expand All @@ -68,7 +69,6 @@ export default ({config}: ConfigContext): ExpoConfig => ({
},
],
'expo-localization',
'@react-native-google-signin/google-signin',
],
experiments: {
typedRoutes: true,
Expand All @@ -81,9 +81,6 @@ export default ({config}: ConfigContext): ExpoConfig => ({
extra: {
supabaseUrl: process.env.supabaseUrl,
supabaseAnonKey: process.env.supabaseAnonKey,
googleClientIdAndroid: process.env.googleClientIdAndroid,
googleClientIdIOS: process.env.googleClientIdIOS,
googleClientIdWeb: process.env.googleClientIdWeb,
eas: {projectId: '1a0107b0-1cef-4913-875f-639c38f59101'},
},
updates: {
Expand Down
10 changes: 0 additions & 10 deletions app/(app)/_layout.tsx

This file was deleted.

28 changes: 21 additions & 7 deletions app/(auth)/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import {Redirect, Stack} from 'expo-router';
import {useRecoilValue} from 'recoil';
import {authRecoilState} from '../../src/recoil/atoms';
import {Stack} from 'expo-router/stack';
import {useDooboo} from 'dooboo-ui';
import {Redirect} from 'expo-router';
import {useAuth} from '@clerk/clerk-expo';

export default function AuthLayout() {
const {authId} = useRecoilValue(authRecoilState);
const {theme} = useDooboo();
const {isSignedIn} = useAuth();

if (authId) {
return <Redirect href={'/'} />;
if (isSignedIn) {
return <Redirect href={'/(tabs)'} />;
}

return <Stack />;
return (
<Stack
initialRouteName="intro"
screenOptions={{
headerStyle: {backgroundColor: theme.bg.basic},
headerTintColor: theme.text.label,
headerTitleStyle: {
fontWeight: 'bold',
color: theme.text.basic,
},
}}
/>
);
}
153 changes: 153 additions & 0 deletions app/(auth)/intro.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import {Image, ScrollView, View} from 'react-native';
import * as WebBrowser from 'expo-web-browser';

import styled, {css} from '@emotion/native';

import {Typography, useDooboo} from 'dooboo-ui';
import {Stack, useRouter} from 'expo-router';

import {IMG_CROSSPLATFORMS, IC_ICON} from '../../src/icons';
import {t} from '../../src/STRINGS';
import {useSafeAreaInsets} from 'react-native-safe-area-context';
import ButtonSocialSignIn from '../../src/components/uis/ButtonSocialSignIn';
import {useWarmUpBrowser} from '../../src/hooks/useWarmUpBrowser';

WebBrowser.maybeCompleteAuthSession();

const Container = styled.View`
flex: 1;
align-self: stretch;
background-color: ${({theme}) => theme.brand};
justify-content: center;
align-items: center;
`;

const Content = styled.View`
flex: 1;
align-self: stretch;
`;

const Buttons = styled.View`
align-self: center;
margin-top: 8px;
padding: 20px;
gap: 12px;
position: absolute;
bottom: 20px;
`;

//* This should be placed in page component or won't work
WebBrowser.maybeCompleteAuthSession();

export default function Intro(): JSX.Element {
useWarmUpBrowser();

const {theme} = useDooboo();
const {push} = useRouter();
const {top, bottom, left, right} = useSafeAreaInsets();

return (
<Container>
<Stack.Screen options={{headerShown: false}} />
<Content style={css``}>
<ScrollView
contentContainerStyle={css`
padding-top: ${top + 32 + 'px'};
padding-bottom: ${bottom + 'px'};
padding-left: ${left + 'px'};
padding-right: ${right + 'px'};
align-items: center;
gap: 12px;
`}
>
<Image
source={IC_ICON}
style={css`
align-self: center;
width: 80px;
height: 80px;
`}
/>

<Typography.Heading3
style={css`
margin-top: 8px;
padding: 0 16px;
color: ${theme.text.basic};
text-align: center;
`}
>
{t('common.appName')}
</Typography.Heading3>
<Typography.Body2
style={css`
padding: 0 16px;
margin-top: -4px;
color: ${theme.text.label};
font-size: 16px;
text-align: center;
line-height: 22px;
`}
>
{t('signIn.description')}
</Typography.Body2>
<Image
source={IMG_CROSSPLATFORMS}
style={css`
margin-top: 24px;
`}
/>
<View
style={css`
height: 220px;
`}
/>
</ScrollView>
<Buttons>
<ButtonSocialSignIn strategy="oauth_github" />
<ButtonSocialSignIn strategy="oauth_google" />
<ButtonSocialSignIn strategy="oauth_apple" />
<Typography.Body4
style={css`
margin-top: 4px;
text-align: center;
line-height: 20px;
color: ${theme.text.label};
`}
>
{t('signIn.policyAgreement', {
termsOfService: `**${t('signIn.termsOfService')}**`,
privacyPolicy: `**${t('signIn.privacyPolicy')}**`,
})
.split('**')
.map((str, i) =>
i % 2 === 0 ? (
str
) : (
<Typography.Body4
key={str}
onPress={() => {
if (str === t('signIn.privacyPolicy')) {
return push('/privacyandpolicy');
}

push('/termsofservice');
}}
style={css`
text-decoration-line: underline;
color: ${theme.text.basic};
text-decoration-line: underline;
`}
>
{str}
</Typography.Body4>
),
)}
</Typography.Body4>
</Buttons>
</Content>
</Container>
);
}
Loading

0 comments on commit a763aae

Please sign in to comment.