webfox / laravel-xero-oauth2

A Laravel integration for Xero using the Oauth 2.0 spec
MIT License
50 stars 32 forks source link

Support loading credentials from model other than authenticated user. #123

Open hailwood opened 6 days ago

hailwood commented 6 days ago

One of the developers at work has been using the beta version and ran into an interesting scenario - they wanted a per user storage, but not directly on the user.

In this case it was - user belongs to organisation, so we want the organisations xero credentials.

@JamesFreeman suggested

Yeah, thinking this through at the moment, users would not be able to provide a dynamic model selection. I was thinking as a potential solution, users could provide a callback on the useModelStore for selection.

Xero::useModelStore(Team::class, fn($builder) => $builder->where('id', Auth::user()->currentTeamId));

If you're happy with this pr, let's get it merged in, and I'll create a new task for this. 👍

JamesFreeman commented 3 days ago

I don't think this is necessary, I believe we can do it with what we have already.

Xero::useModelStorage(Team::find(Auth::user()->currentTeamId)),

It would be recommended to put this in the middleware instead of the App service provider tho.