Skip to content

Instantly share code, notes, and snippets.

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()
var csfr = data
return {csfr};
export let csfr;
async function handleClick() {
// alert('clicked')
await valid_token()
async function valid_token(){
try {
var item = {
_token: csfr._token,
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) {
<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