Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { useEffect } from 'react'
import { getLogoutURL, AuthIsDisabled } from '../../lib/auth'
import { GetServerSidePropsContext } from 'next'
import LoadingSpinner from '../../components/LoadingSpinner'
import MetaData from '../../components/MetaData'
import { getLogger } from '../../logging/log-util'
import React from 'react'
import { deleteAllCookiesWithPrefix } from '../../lib/cookie-utils'
 
interface MetaDataProps {
  data_en: {
    title: string
    desc: string
    author: string
    keywords: string
    service: string
    creator: string
    accessRights: string
  }
  data_fr: {
    title: string
    desc: string
    author: string
    keywords: string
    service: string
    creator: string
    accessRights: string
  }
}
 
interface LogoutProps {
  locale: string
  meta: MetaDataProps
  logoutURL: string
}
export default function Logout(props: LogoutProps) {
  //Redirect to ECAS global sign out
  useEffect(() => {
    const logout = async () => {
      window.location.replace(props.logoutURL)
    }
    logout().catch(console.error)
  }, [props.logoutURL])
 
  return (
    <div role="main">
      <MetaData language="en" data={props.meta}></MetaData>
      <h1
        className="grid h-screen place-items-center"
        data-cy="loading-spinner"
        aria-live="polite"
        aria-busy="true"
      >
        <LoadingSpinner text="Loading / Chargement en cours ..." />
      </h1>
    </div>
  )
}
 
Logout.getLayout = function PageLayout(page: JSX.Element) {
  return <>{page}</>
}
 
export async function getServerSideProps({
  req,
  res,
  locale,
}: {
  req: GetServerSidePropsContext['req']
  res: GetServerSidePropsContext['res']
  locale: GetServerSidePropsContext['locale']
}) {
  //The below sets the minimum logging level to error and surpresses everything below that
  const logger = getLogger('logout')
  logger.level = 'error'
 
  deleteAllCookiesWithPrefix(
    req,
    res,
    process.env.AUTH_COOKIES_PREFIX as string,
  )
 
  const logoutURL = !AuthIsDisabled()
    ? await getLogoutURL(req.cookies, locale).catch((error) => {
        logger.error(error)
        res.statusCode = 500
        throw error
      })
    : '/'
 
  /* Place-holder Meta Data Props */
  const meta = {
    data_en: {
      title: 'Loading-Chargement en cours - Canada.ca',
      desc: 'English',
      author: 'Service Canada',
      keywords: '',
      service: 'ESDC-EDSC_MSCA-MSDC-SCH',
      creator: 'Employment and Social Development Canada',
      accessRights: '1',
    },
    data_fr: {
      title: 'Loading-Chargement en cours - Canada.ca',
      desc: 'Français',
      author: 'Service Canada',
      keywords: '',
      service: 'ESDC-EDSC_MSCA-MSDC-SCH',
      creator: 'Emploi et Développement social Canada',
      accessRights: '1',
    },
  }
 
  return {
    props: {
      locale: locale,
      meta,
      logoutURL: logoutURL,
    },
  }
}
  |