All routes are registered under the prefix set in routes.prefix and named with a larascord. prefix.
| Route Name | URI | Description | Action | Method |
|---|---|---|---|---|
larascord.redirect | /larascord/redirect | Redirects the user to Discord's OAuth2 authorization page. | DiscordController@redirect | GET |
larascord.callback | /larascord/callback | Callback route for Discord OAuth2 authentication. | DiscordController@callback | GET |
larascord.logout | /larascord/logout | Invalidates the current session. | DiscordController@logout | POST |
larascord.link | /larascord/link | Links a Discord account to the authenticated user. | DiscordController@link | GET |
larascord.unlink | /larascord/unlink | Revokes the access token and unlinks the Discord account. | DiscordController@unlink | DELETE |
The larascord.link and larascord.unlink routes use the middleware set in routes.authenticated_middleware, which defaults to web and auth. The remaining routes use routes.middleware, which defaults to web.
Return URL
The return URL is resolved when the flow starts and stored in the session, because at the end of the flow the previous URL recorded by the session is the route that started it.
The first of the following that applies is used:
The redirect_to query parameter
<a href="{{ route('larascord.redirect', ['redirect_to' => url()->current()]) }}">Log in with Discord</a>The previous URL, for larascord.link only
The URL stored by Laravel's auth middleware
The redirect_login option
A return URL on a different host, or on one of Larascord's own routes, is discarded and the next option is used.
Authenticated users
larascord.redirect and the login alias are login routes regardless of whether a session exists. The Discord profile is updated, the session is kept when the resolved user matches the authenticated user, and the resolved user is logged in when it does not.
Use larascord.link to attach a Discord account to the authenticated user.
The login route alias
Laravel's auth middleware redirects guests to a route named login. Larascord registers GET /login, named login, when LARASCORD_LOGIN_ALIAS is enabled.
LARASCORD_LOGIN_ALIAS=trueRegistering the routes manually
Set routes.enabled to false and point your own routes at the controller.
use Jakyeru\Larascord\Http\Controllers\DiscordController;
Route::get('/auth/discord', [DiscordController::class, 'redirect'])->name('larascord.redirect');
Route::get('/auth/discord/callback', [DiscordController::class, 'callback'])->name('larascord.callback');Keep the larascord.redirect and larascord.callback route names. The redirect_uri option in config/larascord.php must match the URI of your callback route and the redirect url registered with Discord.