@heymarco/next-auth
Version:
A complete authentication solution for web applications.
89 lines (88 loc) • 3.67 kB
JavaScript
'use client';
// react:
import {
// react:
default as React, } from 'react';
// utilities:
export const invalidSelector = ':is(.invalidating, .invalidated)';
export const getAuthErrorDescription = (errorCode) => {
switch (errorCode) {
case 'SessionRequired': // the content of this page requires you to be signed in at all times
return React.createElement("p", null,
"You are not signed in. Please ",
React.createElement("strong", null, "sign in to continue"),
".");
case 'CredentialsSignin': // the authorize callback returned null in the Credentials provider
return React.createElement("p", null,
"Sign in failed. Make sure ",
React.createElement("strong", null, "your username (or email)"),
" and ",
React.createElement("strong", null, "your password"),
" are correct.");
case 'OAuthSignin': // error in constructing an authorization URL
case 'OAuthCallback': // error in handling the response from an OAuth provider
case 'OAuthCreateAccount': // could not create OAuth provider user in the database
case 'Callback': // error in the OAuth callback handler route
return React.createElement("p", null,
"Sign in failed. Make sure you have ",
React.createElement("strong", null, "granted access"),
" from your 3rd party account.");
case 'AccessDenied':
return React.createElement("p", null,
"You do ",
React.createElement("strong", null, "not have permission"),
" to sign in.");
case 'Verification':
return React.createElement("p", null,
"The token has ",
React.createElement("strong", null, "expired"),
" or has ",
React.createElement("strong", null, "already been used"),
".");
case 'Configuration':
return React.createElement(React.Fragment, null,
React.createElement("p", null,
"There is a problem with the ",
React.createElement("strong", null, "server configuration"),
"."),
React.createElement("p", null, "Please contact our technical support for assistance."));
case 'Default':
default:
return React.createElement("p", null,
"Oops, an ",
React.createElement("strong", null, "error occured"),
".");
} // switch
};
export const resolveProviderName = (oAuthProvider) => {
return oAuthProvider.replace(/((?:^| )[a-z])/g, (found) => found.toUpperCase());
};
export const getValidityTheme = (isValid) => {
switch (isValid) {
case true: return 'success';
case false: return 'danger';
case 'unknown': return 'danger';
default: return 'secondary';
} // switch
};
export const getValidityIcon = (isValid) => {
switch (isValid) {
case true: return 'check';
case false: return 'error_outline';
case 'loading': return 'busy';
case 'unknown': return 'help_outline';
default: return 'help_outline';
} // switch
};
export const isClientError = (fetchError) => {
const errorCode = (fetchError?.status
??
fetchError?.cause?.status);
if (typeof (errorCode) !== 'number')
return false;
return (errorCode >= 400) && (errorCode <= 499);
};
// handlers:
export const handlePreventSubmit = (event) => {
event.preventDefault();
};