)
// verify identity of the authenticated user with the Microsoft Graph API
const { data, status } = await getAuthPersonInfo(accessToken)
if (status !== 200) {
setButtonError(true)
setButtonContent(
{t('Error validating identify, restart')}
)
return
}
if (data.userPrincipalName !== siteConfig.userPrincipalName) {
setButtonError(true)
setButtonContent(
{' '}
{t('These tokens may take a few seconds to populate after you click the button below. ') +
t('If you go back home and still see the welcome page telling you to re-authenticate, ') +
t('revisit home and do a hard refresh.')}
{t(
'Final step, click the button below to store these tokens persistently before they expire after {{minutes}} minutes {{seconds}} seconds. ',
{
minutes: Math.floor(expiryTimeLeft / 60),
seconds: expiryTimeLeft - Math.floor(expiryTimeLeft / 60) * 60,
}
) +
t(
"Don't worry, after storing them, onedrive-vercel-index will take care of token refreshes and updates after your site goes live."
)}
)}
)
}
export async function getServerSideProps({ query, locale }) {
const { authCode } = query
// Return if no auth code is present
if (!authCode) {
return {
props: {
error: 'No auth code present',
description: 'Where is the auth code? Did you follow step 2 you silly donut?',
...(await serverSideTranslations(locale, ['common'])),
},
}
}
const response = await requestTokenWithAuthCode(authCode)
// If error response, return invalid
if ('error' in response) {
return {
props: {
error: response.error,
description: response.errorDescription,
errorUri: response.errorUri,
...(await serverSideTranslations(locale, ['common'])),
},
}
}
const { expiryTime, accessToken, refreshToken } = response
return {
props: {
error: null,
expiryTime,
accessToken,
refreshToken,
...(await serverSideTranslations(locale, ['common'])),
},
}
}