Routes

All routes are registered under the prefix set in routes.prefix and named with a larascord. prefix.

Route NameURIDescriptionActionMethod
larascord.redirect/larascord/redirectRedirects the user to Discord's OAuth2 authorization page.DiscordController@redirectGET
larascord.callback/larascord/callbackCallback route for Discord OAuth2 authentication.DiscordController@callbackGET
larascord.logout/larascord/logoutInvalidates the current session.DiscordController@logoutPOST
larascord.link/larascord/linkLinks a Discord account to the authenticated user.DiscordController@linkGET
larascord.unlink/larascord/unlinkRevokes the access token and unlinks the Discord account.DiscordController@unlinkDELETE

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.

.env
LARASCORD_LOGIN_ALIAS=true

Registering the routes manually

Set routes.enabled to false and point your own routes at the controller.

routes/web.php
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.