feat: attempt to fix the crud with auth

This commit is contained in:
Riccardo
2024-07-07 17:47:57 +02:00
parent ea73368cc9
commit 637520dbf2
27 changed files with 622 additions and 53 deletions

View File

@@ -1,6 +1,7 @@
'use client';
import { withPageAuthRequired } from '@auth0/nextjs-auth0/client';
import axios from 'axios';
import { useEffect, useState } from 'react';
export default withPageAuthRequired(function Profile() {
@@ -8,18 +9,16 @@ export default withPageAuthRequired(function Profile() {
useEffect(() => {
(async () => {
const res = await fetch(
`${window.location.origin}/api/protected/profile`
);
setUser(await res.json());
const response = await axios.get('/api/protected/profile');
setUser(response.data);
})();
}, []);
return (
<main>
<>
<h1>Profile (fetched from API)</h1>
<h3>User</h3>
<pre data-testid='module'>{JSON.stringify(user, null, 2)}</pre>
</main>
{JSON.stringify(user, null, 2)}
</>
);
});