UNPKG

next-auth

Version:

Authentication for Next.js

102 lines (97 loc) 3.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = signin; var _preact = require("preact"); function signin({ csrfToken, providers, callbackUrl, email, error: errorType }) { var _errors$errorType; const providersToRender = providers.filter(provider => { if (provider.type === "oauth" || provider.type === "email") { return true; } else if (provider.type === "credentials" && provider.credentials) { return true; } return false; }); const errors = { Signin: "Try signing in with a different account.", OAuthSignin: "Try signing in with a different account.", OAuthCallback: "Try signing in with a different account.", OAuthCreateAccount: "Try signing in with a different account.", EmailCreateAccount: "Try signing in with a different account.", Callback: "Try signing in with a different account.", OAuthAccountNotLinked: "To confirm your identity, sign in with the same account you used originally.", EmailSignin: "Check your email inbox.", CredentialsSignin: "Sign in failed. Check the details you provided are correct.", default: "Unable to sign in." }; const error = errorType && ((_errors$errorType = errors[errorType]) !== null && _errors$errorType !== void 0 ? _errors$errorType : errors.default); return (0, _preact.h)("div", { className: "signin" }, error && (0, _preact.h)("div", { className: "error" }, (0, _preact.h)("p", null, error)), providersToRender.map((provider, i) => (0, _preact.h)("div", { key: provider.id, className: "provider" }, provider.type === "oauth" && (0, _preact.h)("form", { action: provider.signinUrl, method: "POST" }, (0, _preact.h)("input", { type: "hidden", name: "csrfToken", value: csrfToken }), callbackUrl && (0, _preact.h)("input", { type: "hidden", name: "callbackUrl", value: callbackUrl }), (0, _preact.h)("button", { type: "submit", className: "button" }, "Sign in with ", provider.name)), (provider.type === "email" || provider.type === "credentials") && i > 0 && providersToRender[i - 1].type !== "email" && providersToRender[i - 1].type !== "credentials" && (0, _preact.h)("hr", null), provider.type === "email" && (0, _preact.h)("form", { action: provider.signinUrl, method: "POST" }, (0, _preact.h)("input", { type: "hidden", name: "csrfToken", value: csrfToken }), (0, _preact.h)("label", { for: `input-email-for-${provider.id}-provider` }, "Email"), (0, _preact.h)("input", { id: `input-email-for-${provider.id}-provider`, autoFocus: true, type: "text", name: "email", value: email, placeholder: "email@example.com" }), (0, _preact.h)("button", { type: "submit" }, "Sign in with ", provider.name)), provider.type === "credentials" && (0, _preact.h)("form", { action: provider.callbackUrl, method: "POST" }, (0, _preact.h)("input", { type: "hidden", name: "csrfToken", value: csrfToken }), Object.keys(provider.credentials).map(credential => { return (0, _preact.h)("div", { key: `input-group-${provider.id}` }, (0, _preact.h)("label", { for: `input-${credential}-for-${provider.id}-provider` }, provider.credentials[credential].label || credential), (0, _preact.h)("input", { name: credential, id: `input-${credential}-for-${provider.id}-provider`, type: provider.credentials[credential].type || "text", value: provider.credentials[credential].value || "", placeholder: provider.credentials[credential].placeholder || "" })); }), (0, _preact.h)("button", { type: "submit" }, "Sign in with ", provider.name)), (provider.type === "email" || provider.type === "credentials") && i + 1 < providersToRender.length && (0, _preact.h)("hr", null)))); }