Giter Site home page Giter Site logo

Comments (14)

rustamwin avatar rustamwin commented on August 22, 2024
  1. Remove Authentication middleware from the route.
  2. Use $currentUser->isGuest() in your controller.

from auth.

hiscaler avatar hiscaler commented on August 22, 2024

@rustamwin If remove Authentication middleware in route, $currentUser->isGuest() alway return true.

from auth.

vjik avatar vjik commented on August 22, 2024

@hiscaler You should add optional routes to withOptionalPatterns() method. For example:

Authentication::class => [
        'class' => Authentication::class,
        '__construct()' => [
            'authenticationFailureHandler' => Reference::to(PassportRequestErrorHandler::class),
        ],
        'withOptionalPatterns()' => [
            'optional' => [
                '/en/products/[1-9]',
                'products/product/view', // Don't forget adapt pattern for your case
            ]
        ]
    ],

from auth.

hiscaler avatar hiscaler commented on August 22, 2024

@vjik I will try. Thank you!

from auth.

hiscaler avatar hiscaler commented on August 22, 2024

@vjik Can not.

GET /en/products/1 is return product 1 detail
PUT /en/products/1 is update product 1 detail
DELETE /en/products/1 is delete product 1

but withOptionalPatterns.optional

['/en/products/[1-9]']

can't not know what's request method.

from auth.

hiscaler avatar hiscaler commented on August 22, 2024

and has a other question.

['/en/products/[1-9]{1}']

can't matched /en/products/123

from auth.

rustamwin avatar rustamwin commented on August 22, 2024

@hiscaler see patterns https://github.com/yiisoft/strings/blob/master/README.md#wildcardpattern-usage

from auth.

hiscaler avatar hiscaler commented on August 22, 2024

@rustamwin Thank you!

from auth.

hiscaler avatar hiscaler commented on August 22, 2024

@hiscaler see patterns https://github.com/yiisoft/strings/blob/master/README.md#wildcardpattern-usage

Valid setting is ['/en/products/[1-9]*'] , thank you.

from auth.

hiscaler avatar hiscaler commented on August 22, 2024

@vjik Can not.

GET /en/products/1 is return product 1 detail PUT /en/products/1 is update product 1 detail DELETE /en/products/1 is delete product 1

but withOptionalPatterns.optional

['/en/products/[1-9]']

can't not know what's request method.

So i think should add check request method in Authentication.isOptional

from auth.

vjik avatar vjik commented on August 22, 2024

@hiscaler you want make optional authentication for GET request only and otherwise required (POST, DELETE, etc.)?

from auth.

hiscaler avatar hiscaler commented on August 22, 2024

@vjik yes, is only GET request, POST, DELETE is must authentication

from auth.

vjik avatar vjik commented on August 22, 2024

Need add ability to specify request type in optional patterns.

from auth.

vjik avatar vjik commented on August 22, 2024

Another idea: leave in Authentication middleware authentication process only and create new middleawre that will be throw exception or return response "No access".

from auth.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.