From 267720fe94ca342d38985079d3c84bdad47933cb Mon Sep 17 00:00:00 2001 From: juliusmarminge Date: Thu, 2 Nov 2023 01:40:54 +0100 Subject: [PATCH] feat: expo auth --- apps/expo/package.json | 2 + apps/expo/src/app/index.tsx | 14 ++++ apps/expo/src/utils/api.tsx | 8 ++- apps/expo/src/utils/auth-hooks.tsx | 48 +++++++++++++ apps/expo/src/utils/session-store.ts | 6 ++ .../src/app/api/auth/[...nextauth]/route.ts | 47 +++++++++++- packages/api/src/router/auth.ts | 9 +++ packages/api/src/trpc.ts | 13 ++-- packages/auth/index.ts | 23 +++++- pnpm-lock.yaml | 71 +++++++++++++++++++ 10 files changed, 233 insertions(+), 8 deletions(-) create mode 100644 apps/expo/src/utils/auth-hooks.tsx create mode 100644 apps/expo/src/utils/session-store.ts diff --git a/apps/expo/package.json b/apps/expo/package.json index 1db92aa615..f7598aa1dc 100644 --- a/apps/expo/package.json +++ b/apps/expo/package.json @@ -25,8 +25,10 @@ "expo-constants": "~14.4.2", "expo-linking": "~5.0.2", "expo-router": "2.0.10", + "expo-secure-store": "^12.5.0", "expo-splash-screen": "~0.22.0", "expo-status-bar": "~1.7.1", + "expo-web-browser": "^12.5.0", "nativewind": "^4.0.1", "react": "18.2.0", "react-dom": "18.2.0", diff --git a/apps/expo/src/app/index.tsx b/apps/expo/src/app/index.tsx index d67633129b..ff867c8792 100644 --- a/apps/expo/src/app/index.tsx +++ b/apps/expo/src/app/index.tsx @@ -13,6 +13,7 @@ import { FlashList } from "@shopify/flash-list"; import { api } from "~/utils/api"; import type { RouterOutputs } from "~/utils/api"; +import { useSignIn, useSignOut, useUser } from "~/utils/auth-hooks"; function PostCard(props: { post: RouterOutputs["post"]["all"][number]; @@ -108,6 +109,10 @@ const Index = () => { const postQuery = api.post.all.useQuery(); + const user = useUser(); + const signIn = useSignIn(); + const signOut = useSignOut(); + const deletePostMutation = api.post.delete.useMutation({ onSettled: () => utils.post.all.invalidate(), }); @@ -127,6 +132,15 @@ const Index = () => { color={"#f472b6"} /> + + {user?.name ?? "Not logged in"} + +