mirror of
https://github.com/kevin-DL/sapper-template.git
synced 2026-01-18 20:55:05 +00:00
Work on signup. Removed polka, using express since passport was being weird
This commit is contained in:
34
routes/auth/validate.json.js
Normal file
34
routes/auth/validate.json.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import db from '../../app/auth/db'
|
||||
import emailRegex from './_email-regex'
|
||||
|
||||
|
||||
export async function post(req, res) {
|
||||
let message = '';
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
try {
|
||||
if (req.body.key === 'username') {
|
||||
debugger
|
||||
const found = db.find(req.body.key, req.body.value);
|
||||
if (found) {
|
||||
message = 'That username is already in use.';
|
||||
}
|
||||
res.end(JSON.stringify({ valid: !found, message }));
|
||||
} else if (req.body.key === 'email') {
|
||||
let valid = emailRegex.test(req.body.value);
|
||||
if (!valid) {
|
||||
message = 'Email is invalid.';
|
||||
} else {
|
||||
debugger
|
||||
const found = db.find(req.body.key, req.body.value);
|
||||
if (found) {
|
||||
message = 'Email is already taken.';
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
res.end(JSON.stringify({ valid, message }));
|
||||
}
|
||||
res.end({ valid: false, message: 'Something went wrong. Please <a href="/contact">contact us</a> for help.' });
|
||||
} catch (error) {
|
||||
res.end({ valid: false, message: 'Something went wrong. Please <a href="/contact">contact us</a> for help.' });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user