Created
June 2, 2021 03:22
-
-
Save kuc-arc-f/4200c1e1e2354046b03c2127b423a114 to your computer and use it in GitHub Desktop.
Sapper Flash function
This file contains 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
var csrf = require('csrf'); | |
var tokens = new csrf(); | |
// | |
export default { | |
set_falsh:async function(req, flash_message){ | |
try{ | |
//console.log(flash_message) | |
var arr = {message:'', error:''} | |
if( typeof flash_message.message != 'undefined'){ | |
arr.message= flash_message.message | |
req.session.flash = arr; | |
} | |
} catch (e) { | |
console.log(e); | |
throw new Error('error, set_falsh'); | |
} | |
}, | |
get_falsh:async function(req){ | |
try{ | |
//console.log(flash_message) | |
var arr = {message:'', error:''} | |
if(typeof req.session.flash == 'undefined'){ | |
return arr | |
} | |
const flash_message = req.session.flash | |
if( typeof flash_message.message != 'undefined'){ | |
arr.message= flash_message.message | |
} | |
if( typeof flash_message.error != 'undefined'){ | |
arr.error= flash_message.error | |
} | |
delete req.session.flash; | |
return arr | |
} catch (e) { | |
console.log(e); | |
throw new Error('error, get_falsh'); | |
} | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment