Skip to content

Commit

Permalink
feat: add csrf method
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Oct 2, 2024
1 parent 54d3b5d commit 94823fa
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,27 @@ public function cors($options = [])
}
}

/**
* Add CSRF protection to your app
*
* @param array $options Config for csrf
*/
public function csrf($options = [])
{
if (!\class_exists('Leaf\Anchor\CSRF')) {
\trigger_error('CSRF module not found! Run `leaf install csrf` or `composer require leafs/csrf` to install the CSRF module. This is required to configure CSRF.');
}

if (!Anchor\CSRF::token()) {
Anchor\CSRF::init();
Anchor\CSRF::config($options);
}

$this->use(function () {
Anchor\CSRF::validate();
});
}

/**
* Create a route handled by websocket (requires Eien module)
*
Expand Down

0 comments on commit 94823fa

Please sign in to comment.