T
T
tincap2019-03-16 22:11:41
Laravel
tincap, 2019-03-16 22:11:41

How to pull out the user in Laravel JWT if there is a token?

I use JWT Laravel https://github.com/tymondesigns/jwt-auth

public function refresh()
    {
        $newToken = auth()->refresh();

        return response()->json([
            'status' => 'ok',
            'user' => [
                'id' => auth()->user()->id,
                'email' => auth()->user()->email,
            ]
        ]
    }

This code will throw an error because auth()->user() == null
How do I get the user if there is a refreshed token?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
T
tincap, 2019-03-17
@tincap

$newToken = auth()->refresh();
$user = auth()->setToken($newToken)->user();

A
Alexander, 2016-11-25
@xpert13

This is a Borlad VCL problem. On Delphi, the same thing (which is not strange, because the same VCL is used).
The modal window is hidden when the window is minimized/maximized. The following recipe helped me at one time: for a modal window, add the following code (code in Delphi, I think you can translate it):

type
  TfrmModal = class(TForm)
  private
    procedure WMSYSCOMMAND(var Msg: TWMSYSCOMMAND); message WM_SYSCOMMAND;
  end;

...

procedure TfrmModal.WMSYSCOMMAND(var Msg: TWMSYSCOMMAND);
begin
  case (Msg.CmdType and $FFF0) of
    SC_MINIMIZE:
    begin
      Msg.Result := 0;
      EnableWindow(Application.Handle, True);
      Application.Minimize;
    end;

    else inherited;
  end;
end;

This procedure can be added to each modal window, or you can create a class with this method, from which all modal windows inherit (instead of TForm).
----
UPD : I'll try to translate into C++, but I can't check:
header:
private: // of TForm1 class
  void __fastcall WMSysCommand(TMessage &Msg); 

BEGIN_MESSAGE_MAP 
    MESSAGE_HANDLER(WM_SYSCOMMAND, TMessage, WMSysCommand) 
END_MESSAGE_MAP(TForm)

cpp:
void __fastcall TForm1::WMSysCommand(TMessage &Msg)
{
    unsigned int const sys_code = Msg.WParam & 0xFFF0;
    switch (sys_code)
    {
        case SC_MINIMIZE:
        {
            Msg.Result = 0;
            EnableWindow(Application.Handle, True);
            Application.Minimize();
            return;
        }
    }
    TForm::Dispatch(&Msg);
}

A
Adamos, 2016-11-25
@Adamos

For example, like this: in the class of the parent window, get a member - a pointer to the modal dialog. It should be NULL by default and when closing dialogs.
In the update / draw / idle method (which you can override there), check if this member has a value. If there is, send him ToTop or whatever it is called by Borland.
More or less like this.
You can still play around with setting the main window to Enable(false) when opening a dialog, but this is already shamanism, and on another computer the behavior may be different.
You have a problem, most likely, because of the miracles of the Eight-Ten window manager, which did not figure out that the dialog is modal and it is not necessary to consider it as a separate window.

S
sitev_ru, 2016-11-25
@sitev_ru

Very strange... In theory, they cannot hide, since they are modal... How do you call them? Show Modal?
But if this is the case, you can try the following actions:
1. For each window, intercept the event of hiding the modal window and display it on top of all windows
2. Do the same with a timer. Set, for example, 200 - 500 ms. Of course, to do it on a timer, this is out of hopelessness))
3. Switch to a more or less latest version of the builder

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question