Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
sapper csrf test
<script context="module">
import axios from 'axios'
export async function preload() {
var url ="/api/get_token";
const res = await this.fetch(url)
const data = await res.json()
//console.log(data)
var csfr = data
return {csfr};
}
</script>
<script>
export let csfr;
console.log(csfr)
async function handleClick() {
// alert('clicked')
await valid_token()
}
async function valid_token(){
try {
var item = {
_token: csfr._token,
}
console.log(item)
const res = await fetch( '/api/valid_csrf', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(item),
});
if (res.status != 200) {
throw new Error(await res.text());
}
console.log(await res.json())
} catch (error) {
console.error(error);
}
}
</script>
<svelte:head>
<title>test</title>
</svelte:head>
<h1>test</h1>
<p>token={csfr._token}</p>
<hr />
<button on:click={handleClick}>valid_token</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment