-
-
Save randohinn/58534c774282bdff14904b3c21aa9926 to your computer and use it in GitHub Desktop.
kratos self service register flow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const globals = require('../globals'); | |
const frontend = globals.frontend; | |
function customSort(a, b) { | |
const nameA = a.attributes.name; | |
const nameB = b.attributes.name; | |
const aContainsEmail = nameA.includes("email"); | |
const bContainsEmail = nameB.includes("email"); | |
const aContainsPassword = nameA.includes("password"); | |
const bContainsPassword = nameB.includes("password"); | |
const aIsAgreement = nameA.startsWith("traits.agreements"); | |
const bIsAgreement = nameB.startsWith("traits.agreements"); | |
const aContainsFirstName = nameA.includes("traits.name.first"); | |
const bContainsFirstName = nameB.includes("traits.name.first"); | |
const aContainsLastName = nameA.includes("traits.name.last"); | |
const bContainsLastName = nameB.includes("traits.name.last"); | |
if (aContainsFirstName && bContainsLastName) { | |
return -1; // a comes before b | |
} else if (aContainsLastName && bContainsFirstName) { | |
return 1; // a comes after b | |
} else if ((aContainsFirstName || aContainsLastName) && !(bContainsFirstName || bContainsLastName)) { | |
return -1; // a comes before b | |
} else if (!(aContainsFirstName || aContainsLastName) && (bContainsFirstName || bContainsLastName)) { | |
return 1; // a comes after b | |
} else if (aContainsEmail && !bContainsEmail) { | |
return -1; // a comes before b | |
} else if (!aContainsEmail && bContainsEmail) { | |
return 1; // a comes after b | |
} else if (aContainsPassword && !bContainsPassword) { | |
return -1; // a comes before b | |
} else if (!aContainsPassword && bContainsPassword) { | |
return 1; // a comes after b | |
} else if (aIsAgreement && !bIsAgreement) { | |
return -1; // a comes before b | |
} else if (!aIsAgreement && bIsAgreement) { | |
return 1; // a comes after b | |
} else { | |
return 0; // no specific order | |
} | |
} | |
module.exports = function(app) { | |
app.get('/registration',function(req, res) { | |
const { | |
flow, | |
return_to, | |
after_verification_return_to, | |
login_challenge, | |
organization, | |
} = req.query | |
const initFlowQuery = new URLSearchParams({ | |
...(return_to && { return_to: return_to.toString() }), | |
...(organization && { organization: organization.toString() }), | |
...(after_verification_return_to && { | |
after_verification_return_to: after_verification_return_to.toString(), | |
}), | |
}) | |
if (globals.isQuerySet(login_challenge)) { | |
initFlowQuery.append("login_challenge", login_challenge) | |
} | |
if (!globals.isQuerySet(flow)) { | |
res.redirect(303, globals.getUrlForFlow(process.env.KRATOS_BROWSER_URL || "localhost:4433",'registration',initFlowQuery)); | |
return | |
} | |
frontend.getRegistrationFlow({id: flow, cookie: req.header("cookie")}).then(async ({ data: flow }) => { | |
res.render('registration', { | |
flow: flow, | |
nodes: flow.ui.nodes.slice().sort(customSort), | |
title: `Registreeru - AHHAA Konto`, | |
session: req.session, | |
}); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment