27 lines
668 B
JavaScript
27 lines
668 B
JavaScript
const rawTokenPattern = /^[A-Za-z0-9_-]{43}$/
|
|
const phoenixSignedTokenPattern = /^SFMyNTY\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]{43}$/
|
|
|
|
const phoenixSignedTokenForms = new Set([
|
|
"support-confirmation-fragment-form",
|
|
"content-removal-confirmation-fragment-form"
|
|
])
|
|
|
|
const rawTokenForms = new Set([
|
|
"magic-link-fragment-form",
|
|
"email-change-fragment-form"
|
|
])
|
|
|
|
export const isProtectedFragmentTokenForForm = (formID, token) => {
|
|
if (typeof token !== "string") return false
|
|
|
|
if (phoenixSignedTokenForms.has(formID)) {
|
|
return phoenixSignedTokenPattern.test(token)
|
|
}
|
|
|
|
if (rawTokenForms.has(formID)) {
|
|
return rawTokenPattern.test(token)
|
|
}
|
|
|
|
return false
|
|
}
|