Skip to content

Commit

Permalink
Merge pull request #14 from deco-sites/feature/public-page-control
Browse files Browse the repository at this point in the history
created publicpage control
  • Loading branch information
baufaker authored Apr 9, 2024
2 parents d90f9cc + 5c402a7 commit dd7f5e6
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 42 deletions.
43 changes: 43 additions & 0 deletions components/ui/PublicPageControl.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* This component was made to control if user is logged in to access pages
*/

import { useEffect } from "preact/hooks";

export interface Props {
redirectTo?: string;
}

function PublicPageControl(props: Props) {
async function isLogged({ accessToken }: { accessToken: string }) {
try {
const response = await fetch("http://localhost:3000/auth/me", {
method: "GET",
headers: {
"content-type": "application/json",
accept: "application/json",
Authorization: accessToken,
},
}).then((r) => r.json());

const username = response.data.Username;

if (username) {
window.location.href = props.redirectTo || "/meus-dados";
}
} catch (error) {
console.error("Erro ao carregar dados:", error);
}
}

useEffect(() => {
// Pega accessCode no localStorage para verificar se ainda está válida a sessão via api
const accessToken = localStorage.getItem("AccessToken") || "";

isLogged({ accessToken });
}, []); // Passando um array de dependências vazio

return <></>;
}

export default PublicPageControl;
2 changes: 2 additions & 0 deletions fresh.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import * as $Newsletter from "./islands/Newsletter.tsx";
import * as $OutOfStock from "./islands/OutOfStock.tsx";
import * as $PrivatePageControl from "./islands/PrivatePageControl.tsx";
import * as $ProductImageZoom from "./islands/ProductImageZoom.tsx";
import * as $PublicPageControl from "./islands/PublicPageControl.tsx";
import * as $SearchControls from "./islands/SearchControls.tsx";
import * as $ShippingSimulation from "./islands/ShippingSimulation.tsx";
import * as $ShowMore from "./islands/ShowMore.tsx";
Expand Down Expand Up @@ -74,6 +75,7 @@ const manifest = {
"./islands/OutOfStock.tsx": $OutOfStock,
"./islands/PrivatePageControl.tsx": $PrivatePageControl,
"./islands/ProductImageZoom.tsx": $ProductImageZoom,
"./islands/PublicPageControl.tsx": $PublicPageControl,
"./islands/SearchControls.tsx": $SearchControls,
"./islands/ShippingSimulation.tsx": $ShippingSimulation,
"./islands/ShowMore.tsx": $ShowMore,
Expand Down
8 changes: 8 additions & 0 deletions islands/PublicPageControl.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Component from "deco-sites/ecannadeco/components/ui/PublicPageControl.tsx";
import type { Props } from "deco-sites/ecannadeco/components/ui/PublicPageControl.tsx";

function Island(props: Props) {
return <Component {...props} />;
}

export default Island;
87 changes: 45 additions & 42 deletions manifest.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,28 @@ import * as $$$$$$43 from "./sections/Miscellaneous/MyAccount.tsx";
import * as $$$$$$44 from "./sections/Miscellaneous/MyDocs.tsx";
import * as $$$$$$45 from "./sections/Miscellaneous/MyInfo.tsx";
import * as $$$$$$46 from "./sections/Miscellaneous/PrivatePageControl.tsx";
import * as $$$$$$47 from "./sections/Miscellaneous/PublicProfile.tsx";
import * as $$$$$$48 from "./sections/Miscellaneous/SignIn.tsx";
import * as $$$$$$50 from "./sections/Miscellaneous/Signout.tsx";
import * as $$$$$$49 from "./sections/Miscellaneous/SignUp.tsx";
import * as $$$$$$51 from "./sections/Miscellaneous/Slide.tsx";
import * as $$$$$$52 from "./sections/Miscellaneous/UserAlerts.tsx";
import * as $$$$$$53 from "./sections/Newsletter/Newsletter.tsx";
import * as $$$$$$54 from "./sections/Product/ImageGalleryFrontBack.tsx";
import * as $$$$$$55 from "./sections/Product/ImageGallerySlider.tsx";
import * as $$$$$$56 from "./sections/Product/NotFound.tsx";
import * as $$$$$$57 from "./sections/Product/NotFoundChallenge.tsx";
import * as $$$$$$58 from "./sections/Product/ProductDetails.tsx";
import * as $$$$$$59 from "./sections/Product/ProductInfo.tsx";
import * as $$$$$$60 from "./sections/Product/ProductShelf.tsx";
import * as $$$$$$61 from "./sections/Product/ProductShelfTabbed.tsx";
import * as $$$$$$62 from "./sections/Product/SearchResult.tsx";
import * as $$$$$$63 from "./sections/Product/ShelfWithImage.tsx";
import * as $$$$$$64 from "./sections/Product/Wishlist.tsx";
import * as $$$$$$65 from "./sections/Social/InstagramPosts.tsx";
import * as $$$$$$66 from "./sections/Social/WhatsApp.tsx";
import * as $$$$$$67 from "./sections/Theme/Theme.tsx";
import * as $$$$$$47 from "./sections/Miscellaneous/PublicPageControl.tsx";
import * as $$$$$$48 from "./sections/Miscellaneous/PublicProfile.tsx";
import * as $$$$$$49 from "./sections/Miscellaneous/SignIn.tsx";
import * as $$$$$$51 from "./sections/Miscellaneous/Signout.tsx";
import * as $$$$$$50 from "./sections/Miscellaneous/SignUp.tsx";
import * as $$$$$$52 from "./sections/Miscellaneous/Slide.tsx";
import * as $$$$$$53 from "./sections/Miscellaneous/UserAlerts.tsx";
import * as $$$$$$54 from "./sections/Newsletter/Newsletter.tsx";
import * as $$$$$$55 from "./sections/Product/ImageGalleryFrontBack.tsx";
import * as $$$$$$56 from "./sections/Product/ImageGallerySlider.tsx";
import * as $$$$$$57 from "./sections/Product/NotFound.tsx";
import * as $$$$$$58 from "./sections/Product/NotFoundChallenge.tsx";
import * as $$$$$$59 from "./sections/Product/ProductDetails.tsx";
import * as $$$$$$60 from "./sections/Product/ProductInfo.tsx";
import * as $$$$$$61 from "./sections/Product/ProductShelf.tsx";
import * as $$$$$$62 from "./sections/Product/ProductShelfTabbed.tsx";
import * as $$$$$$63 from "./sections/Product/SearchResult.tsx";
import * as $$$$$$64 from "./sections/Product/ShelfWithImage.tsx";
import * as $$$$$$65 from "./sections/Product/Wishlist.tsx";
import * as $$$$$$66 from "./sections/Social/InstagramPosts.tsx";
import * as $$$$$$67 from "./sections/Social/WhatsApp.tsx";
import * as $$$$$$68 from "./sections/Theme/Theme.tsx";

const manifest = {
"loaders": {
Expand Down Expand Up @@ -153,28 +154,30 @@ const manifest = {
"deco-sites/ecannadeco/sections/Miscellaneous/MyInfo.tsx": $$$$$$45,
"deco-sites/ecannadeco/sections/Miscellaneous/PrivatePageControl.tsx":
$$$$$$46,
"deco-sites/ecannadeco/sections/Miscellaneous/PublicProfile.tsx": $$$$$$47,
"deco-sites/ecannadeco/sections/Miscellaneous/SignIn.tsx": $$$$$$48,
"deco-sites/ecannadeco/sections/Miscellaneous/Signout.tsx": $$$$$$50,
"deco-sites/ecannadeco/sections/Miscellaneous/SignUp.tsx": $$$$$$49,
"deco-sites/ecannadeco/sections/Miscellaneous/Slide.tsx": $$$$$$51,
"deco-sites/ecannadeco/sections/Miscellaneous/UserAlerts.tsx": $$$$$$52,
"deco-sites/ecannadeco/sections/Newsletter/Newsletter.tsx": $$$$$$53,
"deco-sites/ecannadeco/sections/Miscellaneous/PublicPageControl.tsx":
$$$$$$47,
"deco-sites/ecannadeco/sections/Miscellaneous/PublicProfile.tsx": $$$$$$48,
"deco-sites/ecannadeco/sections/Miscellaneous/SignIn.tsx": $$$$$$49,
"deco-sites/ecannadeco/sections/Miscellaneous/Signout.tsx": $$$$$$51,
"deco-sites/ecannadeco/sections/Miscellaneous/SignUp.tsx": $$$$$$50,
"deco-sites/ecannadeco/sections/Miscellaneous/Slide.tsx": $$$$$$52,
"deco-sites/ecannadeco/sections/Miscellaneous/UserAlerts.tsx": $$$$$$53,
"deco-sites/ecannadeco/sections/Newsletter/Newsletter.tsx": $$$$$$54,
"deco-sites/ecannadeco/sections/Product/ImageGalleryFrontBack.tsx":
$$$$$$54,
"deco-sites/ecannadeco/sections/Product/ImageGallerySlider.tsx": $$$$$$55,
"deco-sites/ecannadeco/sections/Product/NotFound.tsx": $$$$$$56,
"deco-sites/ecannadeco/sections/Product/NotFoundChallenge.tsx": $$$$$$57,
"deco-sites/ecannadeco/sections/Product/ProductDetails.tsx": $$$$$$58,
"deco-sites/ecannadeco/sections/Product/ProductInfo.tsx": $$$$$$59,
"deco-sites/ecannadeco/sections/Product/ProductShelf.tsx": $$$$$$60,
"deco-sites/ecannadeco/sections/Product/ProductShelfTabbed.tsx": $$$$$$61,
"deco-sites/ecannadeco/sections/Product/SearchResult.tsx": $$$$$$62,
"deco-sites/ecannadeco/sections/Product/ShelfWithImage.tsx": $$$$$$63,
"deco-sites/ecannadeco/sections/Product/Wishlist.tsx": $$$$$$64,
"deco-sites/ecannadeco/sections/Social/InstagramPosts.tsx": $$$$$$65,
"deco-sites/ecannadeco/sections/Social/WhatsApp.tsx": $$$$$$66,
"deco-sites/ecannadeco/sections/Theme/Theme.tsx": $$$$$$67,
$$$$$$55,
"deco-sites/ecannadeco/sections/Product/ImageGallerySlider.tsx": $$$$$$56,
"deco-sites/ecannadeco/sections/Product/NotFound.tsx": $$$$$$57,
"deco-sites/ecannadeco/sections/Product/NotFoundChallenge.tsx": $$$$$$58,
"deco-sites/ecannadeco/sections/Product/ProductDetails.tsx": $$$$$$59,
"deco-sites/ecannadeco/sections/Product/ProductInfo.tsx": $$$$$$60,
"deco-sites/ecannadeco/sections/Product/ProductShelf.tsx": $$$$$$61,
"deco-sites/ecannadeco/sections/Product/ProductShelfTabbed.tsx": $$$$$$62,
"deco-sites/ecannadeco/sections/Product/SearchResult.tsx": $$$$$$63,
"deco-sites/ecannadeco/sections/Product/ShelfWithImage.tsx": $$$$$$64,
"deco-sites/ecannadeco/sections/Product/Wishlist.tsx": $$$$$$65,
"deco-sites/ecannadeco/sections/Social/InstagramPosts.tsx": $$$$$$66,
"deco-sites/ecannadeco/sections/Social/WhatsApp.tsx": $$$$$$67,
"deco-sites/ecannadeco/sections/Theme/Theme.tsx": $$$$$$68,
},
"actions": {
"deco-sites/ecannadeco/actions/changePassword.ts": $$$$$$$$$0,
Expand Down
1 change: 1 addition & 0 deletions sections/Miscellaneous/PublicPageControl.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "deco-sites/ecannadeco/islands/PublicPageControl.tsx";

0 comments on commit dd7f5e6

Please sign in to comment.