Skip to content

Instantly share code, notes, and snippets.

@kuc-arc-f
Created June 2, 2021 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuc-arc-f/4200c1e1e2354046b03c2127b423a114 to your computer and use it in GitHub Desktop.
Save kuc-arc-f/4200c1e1e2354046b03c2127b423a114 to your computer and use it in GitHub Desktop.
Sapper Flash function
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