Module: SolidusJwt::Spree::UserDecorator::ClassMethods

Defined in:
app/decorators/models/solidus_jwt/spree/user_decorator.rb

Instance Method Summary collapse

Instance Method Details

#for_jwt(sub) ⇒ Spree.user_class, NilClass

Find user based on subject claim in our json web token

Examples:

get user token

payload = SolidusJwt.decode(token).first
user = Spree::User.for_jwt(payload['sub'])

Parameters:

  • sub (string)

    The subject claim of jwt

Returns:

  • (Spree.user_class, NilClass)

    If a match is found, returns the user, otherwise, returns nil

See Also:



25
26
27
# File 'app/decorators/models/solidus_jwt/spree/user_decorator.rb', line 25

def for_jwt(sub)
  find_by(id: sub)
end