Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
feat: expose getServerAuth function through the functions entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
karimdaghari authored Oct 30, 2023
1 parent 91c9d3b commit 358946e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-masks-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@marzee/react-auth-amplify": patch
---

feat: expose `getServerAuth` function through the functions entry point
5 changes: 5 additions & 0 deletions .changeset/nice-hotels-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@marzee/react-auth-amplify": minor
---

feat: expose `getServerAuth` function through the functions entry point
2 changes: 1 addition & 1 deletion packages/react-auth-amplify/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ export {
deleteUser,
deleteUserAttributes,
forgotPassword,
getServerAuth,
signIn,
signOut,
signUp,
updateUserAttributes,
type UserAttributes
} from './lib/functions';
export * from './lib/next';
export * from './react/provider';
12 changes: 11 additions & 1 deletion packages/react-auth-amplify/src/lib/functions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Auth } from 'aws-amplify';
import { Auth, withSSRContext } from 'aws-amplify';
import type { GetServerSidePropsContext } from 'next';

type CognitoDefaults = {
/**
Expand Down Expand Up @@ -450,3 +451,12 @@ export async function deleteUser(): Promise<
};
}
}

/**
* @description This is a next.js specific option, it is to be used ONLY inside `getServerSideProps`
*/
export async function getServerAuth(ctx: GetServerSidePropsContext) {
const amplify = withSSRContext({ req: ctx.req });
const auth: typeof Auth = amplify.Auth;
return await getCurrentUser(auth);
}
12 changes: 0 additions & 12 deletions packages/react-auth-amplify/src/lib/next.ts

This file was deleted.

0 comments on commit 358946e

Please sign in to comment.