UNPKG

nextjs-seo-manager

Version:
2 lines (1 loc) 1.88 kB
import{_ as t,a as e}from"./index-1954da99.js";import s from"react";import{connect as a}from"react-redux";import{f as r}from"./firebase-f83deced.js";import{getAuth as i,onAuthStateChanged as o,signInAnonymously as c}from"firebase/auth";import"@reduxjs/toolkit";import"@mui/material";import"firebase/app";const n=i(r);class p extends s.Component{constructor(s){super(s),t(this,"componentDidMount",()=>{o(n,async t=>{t?this.loadUser(t):await c(n)}),n?.currentUser&&this.loadUser(n.currentUser)}),t(this,"loadUser",async t=>{const s=["owner","admin","editor"];let a=e({},t);if(t){const e=await t.getIdTokenResult(!0);if(e?.claims?.[this.props?.seoData?.initial?.projectId]&&s.includes(e?.claims?.[this.props?.seoData?.initial?.projectId]))a.authorizedProject=!0;else if(e?.claims?.[this.props?.seoData?.initial?.projectId]){const t=JSON.parse(e?.claims?.[this.props?.seoData?.initial?.projectId]),s=new Date(t.timeStamp).toISOString();(new Date).toISOString()<s?(a.authorizedProject=!0,a.temporaryAccessExpiresAt=t.timeStamp,a.temporaryAccessPageIds="all"):a.authorizedProject=!1}else{let t=!1,s={};const r=this.props?.seoData?.initial?.projectId,i=this.props?.seoData?.initial?.page?.pageId;if(Object.keys(e?.claims||{}).forEach(a=>{if(a.startsWith(`${r}::`))try{const{timeStamp:i}=JSON.parse(e?.claims?.[a]),o=a.slice(r.length+2);s[o]=i,t=!0}catch{}}),t){if(a.authorizedPages=s,i&&s[i]){const t=new Date(s[i]).toISOString();if((new Date).toISOString()<t){a.authorizedProject=!0;const t=Object.values(s).map(t=>new Date(t).getTime());a.temporaryAccessExpiresAt=t.length>0?new Date(Math.min(...t)).toISOString():null,a.temporaryAccessPageIds=Object.keys(s)}}}else a.authorizedProject=!1}}const r={type:"SET_USER",results:JSON.parse(JSON.stringify(a))};this.props.dispatch(r)}),this.state={}}render(){return null}}var l=a(t=>({user:t.user,seoData:t?.seoData}))(p);export{l as default};