Skip to content

Commit

Permalink
Merge pull request #209 from auth0/feature/with-auth-required
Browse files Browse the repository at this point in the history
Added withCSRAuthRequired HOC [SDK-2120]
  • Loading branch information
adamjmcgrath authored Dec 21, 2020
2 parents e7213f5 + 32fb6b4 commit c0a1b0a
Show file tree
Hide file tree
Showing 27 changed files with 1,048 additions and 922 deletions.
4 changes: 2 additions & 2 deletions examples/api-call-example/pages/_app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react';
import { UserProvider } from '@auth0/nextjs-auth0';

export default function App({ Component, pageProps }) {
// If you've used `withPageAuthRequired`, pageProps.user can pre-populate the hook
// if you haven't used `withPageAuthRequired`, pageProps.user is undefined so the hook
// If you've used `withSSRAuthRequired`, pageProps.user can pre-populate the hook
// if you haven't used `withSSRAuthRequired`, pageProps.user is undefined so the hook
// fetches the user from the API routes
const { user } = pageProps;

Expand Down
5 changes: 3 additions & 2 deletions examples/api-call-example/pages/profile-ssr.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { withPageAuthRequired } from '@auth0/nextjs-auth0';
import { withSSRAuthRequired } from '@auth0/nextjs-auth0';

import Layout from '../components/layout';

export default function Profile({ user }) {
Expand All @@ -15,4 +16,4 @@ export default function Profile({ user }) {
);
}

export const getServerSideProps = withPageAuthRequired({ loginUrl: '/api/login' });
export const getServerSideProps = withSSRAuthRequired({ loginUrl: '/api/login' });
6 changes: 3 additions & 3 deletions examples/api-call-example/pages/profile.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { useUser } from '@auth0/nextjs-auth0';
import { useUser, withCSRAuthRequired } from '@auth0/nextjs-auth0';

import Layout from '../components/layout';

export default function Profile() {
export default withCSRAuthRequired(function Profile() {
const { user, loading } = useUser();

return (
Expand All @@ -20,4 +20,4 @@ export default function Profile() {
)}
</Layout>
);
}
});
5 changes: 3 additions & 2 deletions examples/api-call-example/pages/protected-page.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { useUser, withPageAuthRequired } from '@auth0/nextjs-auth0';
import { useUser, withSSRAuthRequired } from '@auth0/nextjs-auth0';

import Layout from '../components/layout';

export default function ProtectedPage() {
Expand All @@ -21,4 +22,4 @@ export default function ProtectedPage() {
);
}

export const getServerSideProps = withPageAuthRequired({ loginUrl: '/api/login' });
export const getServerSideProps = withSSRAuthRequired({ loginUrl: '/api/login' });
5 changes: 3 additions & 2 deletions examples/basic-example/pages/profile-ssr.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { withPageAuthRequired } from '@auth0/nextjs-auth0';
import { withSSRAuthRequired } from '@auth0/nextjs-auth0';

import Layout from '../components/layout';

const Profile = ({ user }) => (
Expand All @@ -15,4 +16,4 @@ const Profile = ({ user }) => (

export default Profile;

export const getServerSideProps = withPageAuthRequired();
export const getServerSideProps = withSSRAuthRequired();
6 changes: 3 additions & 3 deletions examples/basic-example/pages/profile.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { useUser } from '@auth0/nextjs-auth0';
import { useUser, withCSRAuthRequired } from '@auth0/nextjs-auth0';

import Layout from '../components/layout';

export default function Profile() {
export default withCSRAuthRequired(function Profile() {
const { user, loading } = useUser();

return (
Expand All @@ -20,4 +20,4 @@ export default function Profile() {
)}
</Layout>
);
}
});
5 changes: 3 additions & 2 deletions examples/basic-example/pages/protected-page.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { useUser, withPageAuthRequired } from '@auth0/nextjs-auth0';
import { useUser, withSSRAuthRequired } from '@auth0/nextjs-auth0';

import Layout from '../components/layout';

export default function ProtectedPage() {
Expand All @@ -21,4 +22,4 @@ export default function ProtectedPage() {
);
}

export const getServerSideProps = withPageAuthRequired();
export const getServerSideProps = withSSRAuthRequired();
5 changes: 3 additions & 2 deletions examples/typescript-example/pages/profile-ssr.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { UserProfile, withPageAuthRequired } from '@auth0/nextjs-auth0';
import { UserProfile, withSSRAuthRequired } from '@auth0/nextjs-auth0';

import Layout from '../components/layout';

type ProfileProps = { user: UserProfile };
Expand All @@ -17,4 +18,4 @@ export default function Profile({ user }: ProfileProps): React.ReactElement {
);
}

export const getServerSideProps = withPageAuthRequired();
export const getServerSideProps = withSSRAuthRequired();
6 changes: 3 additions & 3 deletions examples/typescript-example/pages/profile.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { useUser } from '@auth0/nextjs-auth0';
import { useUser, withCSRAuthRequired } from '@auth0/nextjs-auth0';

import Layout from '../components/layout';

export default function Profile(): React.ReactElement {
export default withCSRAuthRequired(function Profile(): React.ReactElement {
const { user, loading } = useUser();

return (
Expand All @@ -20,4 +20,4 @@ export default function Profile(): React.ReactElement {
)}
</Layout>
);
}
});
5 changes: 3 additions & 2 deletions examples/typescript-example/pages/protected-page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { useUser, withPageAuthRequired } from '@auth0/nextjs-auth0';
import { useUser, withSSRAuthRequired } from '@auth0/nextjs-auth0';

import Layout from '../components/layout';

export default function ProtectedPage(): React.ReactElement {
Expand All @@ -21,4 +22,4 @@ export default function ProtectedPage(): React.ReactElement {
);
}

export const getServerSideProps = withPageAuthRequired();
export const getServerSideProps = withSSRAuthRequired();
Loading

0 comments on commit c0a1b0a

Please sign in to comment.