From b919948967d11eaa0954fffd88688223e29e837a Mon Sep 17 00:00:00 2001 From: wangsijie Date: Thu, 21 Jul 2022 21:23:23 +0800 Subject: [PATCH] feat(next): handleAuthRoutes --- .../next-sample/pages/api/logto/[action].ts | 3 + .../next-sample/pages/api/sign-in-callback.ts | 3 - packages/next-sample/pages/api/sign-in.ts | 3 - packages/next-sample/pages/api/sign-out.ts | 3 - packages/next-sample/pages/api/user.ts | 3 - packages/next-sample/pages/index.tsx | 6 +- packages/next-sample/pages/profile-ssr.tsx | 2 +- packages/next-sample/pages/protected.tsx | 2 +- packages/next/src/index.test.ts | 77 ++++++++++++++++++- packages/next/src/index.ts | 28 ++++++- 10 files changed, 109 insertions(+), 21 deletions(-) create mode 100644 packages/next-sample/pages/api/logto/[action].ts delete mode 100644 packages/next-sample/pages/api/sign-in-callback.ts delete mode 100644 packages/next-sample/pages/api/sign-in.ts delete mode 100644 packages/next-sample/pages/api/sign-out.ts delete mode 100644 packages/next-sample/pages/api/user.ts diff --git a/packages/next-sample/pages/api/logto/[action].ts b/packages/next-sample/pages/api/logto/[action].ts new file mode 100644 index 00000000..1ce3265a --- /dev/null +++ b/packages/next-sample/pages/api/logto/[action].ts @@ -0,0 +1,3 @@ +import { logtoClient } from '../../../libraries/logto'; + +export default logtoClient.handleAuthRoutes(); diff --git a/packages/next-sample/pages/api/sign-in-callback.ts b/packages/next-sample/pages/api/sign-in-callback.ts deleted file mode 100644 index 53018887..00000000 --- a/packages/next-sample/pages/api/sign-in-callback.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { logtoClient } from '../../libraries/logto'; - -export default logtoClient.handleSignInCallback(); diff --git a/packages/next-sample/pages/api/sign-in.ts b/packages/next-sample/pages/api/sign-in.ts deleted file mode 100644 index ee1e3928..00000000 --- a/packages/next-sample/pages/api/sign-in.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { logtoClient } from '../../libraries/logto'; - -export default logtoClient.handleSignIn(); diff --git a/packages/next-sample/pages/api/sign-out.ts b/packages/next-sample/pages/api/sign-out.ts deleted file mode 100644 index f9bd1291..00000000 --- a/packages/next-sample/pages/api/sign-out.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { logtoClient } from '../../libraries/logto'; - -export default logtoClient.handleSignOut(); diff --git a/packages/next-sample/pages/api/user.ts b/packages/next-sample/pages/api/user.ts deleted file mode 100644 index c7983994..00000000 --- a/packages/next-sample/pages/api/user.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { logtoClient } from '../../libraries/logto'; - -export default logtoClient.handleUser(); diff --git a/packages/next-sample/pages/index.tsx b/packages/next-sample/pages/index.tsx index aa61fe0b..a2e415a3 100644 --- a/packages/next-sample/pages/index.tsx +++ b/packages/next-sample/pages/index.tsx @@ -4,7 +4,7 @@ import { useMemo } from 'react'; import useSWR from 'swr'; const Home = () => { - const { data } = useSWR('/api/user'); + const { data } = useSWR('/api/logto/user'); const { data: protectedResource } = useSWR<{ data: string }>('/api/protected-resource'); const userInfo = useMemo(() => { @@ -42,11 +42,11 @@ const Home = () => {