<?php declare(stricttypes=1); namespace app\helpers; use yii\web\Cookie; //use…
- User
- Assistant
- User
i was showing you my two ideas, I will remove the .env option and stick to having two get functions for accessToken and refresh token that i can call in the cookie jwt helper and elsewhere
- Assistant
- User
what is a 405 error?
(2025-05-22T11:57:45.429Z) [useSignup.ts] submitStage Step: 1 loggerUtils.ts:151:12 XHROPTIONS http://localhost:5000/api/api-signup/stage-one-verify CORS Missing Allow Origin
OPTIONS http://localhost:5000/api/api-signup/stage-one-verify Status 405 Method Not Allowed VersionHTTP/1.1 Transferred301 B (0 B size) Referrer Policystrict-origin-when-cross-origin DNS ResolutionSystem
Allow POST Connection close Content-Type application/json; charset=UTF-8 Date Thu, 22 May 2025 11:57:45 GMT Host localhost:5000 X-Debug-Duration 8 X-Debug-Link /debug/default/view?tag=682f113970eb2 X-Debug-Tag 682f113970eb2 X-Powered-By PHP/8.2.28
Accept / Accept-Encoding gzip, deflate, br, zstd Accept-Language en-US,en;q=0.5 Access-Control-Request-Headers content-type,x-csrf-token Access-Control-Request-Method POST Connection keep-alive DNT 1 Host localhost:5000 Origin Priority u=4 Referer Sec-Fetch-Dest empty Sec-Fetch-Mode cors Sec-Fetch-Site same-site Sec-GPC 1 User-Agent XHRPOST NS_ERROR_DOM_BAD_URI
- Assistant
- User
- Assistant
- User
so add this at the bottom?
$behaviors['authenticator']['except'][] = 'options';
of:
// In ApiSignupController's behaviors() behaviors['authenticator']['except'], [ 'stage-zero-email', 'business-categories', //'stage-one-verify', //'stage-two-credentials', //'stage-three-category', ] );
- Assistant
Exactly!
You can add
'options'to theexceptarray after merging and before returning$behaviors. Like this:// Merge existing except actions $behaviors['authenticator']['except'] = array_merge( $behaviors['authenticator']['except'], [ 'stage-zero-email', 'business-categories', //'stage-one-verify', //'stage-two-credentials', //'stage-three-category', ] ); // Add 'options' HTTP verb to skip auth for CORS preflight $behaviors['authenticator']['except'][] = 'options'; // Remove duplicates just in case $behaviors['authenticator']['except'] = array_unique($behaviors['authenticator']['except']); - User
after few suggested changes, no longer getting a csrf error, but still getting the 405 error
- Assistant
- User
'except' => ['options'], be cap? OPTIONS?
- Assistant
No, it should be lowercase
'options'.Yii's behaviors check the action ID or HTTP method in lowercase (e.g.,
'get','post','options') when matching requests.Using
'OPTIONS'(uppercase) will not work as expected and the behavior will not exclude the preflight requests, resulting in the 405 again.
Summary:
- Use lowercase:
'options' - Example:
'except' => ['options'],
This is consistent with how Yii internal routing and behavior matching work.
- Use lowercase:
- User
/** * Actions * The browser sends a CORS preflight OPTIONS request before the actual cross-origin * request when the request is considered "non-simple". * * Non-simple requests include requests that: * - Use methods other than GET, HEAD, or POST (e.g., PUT, DELETE, PATCH) * - Use certain content types other than application/x-www-form-urlencoded, * multipart/form-data, or text/plain * - Set custom headers like Authorization, X-CSRF-Token, or other non-standard headers */ public function actions() { return [ 'options' => [ 'class' => OptionsAction::class, ], ]; }
- Assistant
Exactly! Your
actions()method correctly registers anoptionsaction using Yii's built-inyii\rest\OptionsActionclass, which is designed specifically to respond to CORS preflightOPTIONSrequests.
What this does:
- Handles any
OPTIONSrequest for your controller's actions.
- Handles any