Move to javascript, save credential works.
Working version. Need cleanup and comments.
Cleanup and explanations.