Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

feat(auth): self-hosted registration gate + admin seeder (closes #46)

Paulo Castellano74bd88d3d63e
diff --git a/app/Http/Controllers/Auth/RegisteredUserController.php b/app/Http/Controllers/Auth/RegisteredUserController.php
index b030065a0..dd13f0f51 100644
--- a/app/Http/Controllers/Auth/RegisteredUserController.php
+++ b/app/Http/Controllers/Auth/RegisteredUserController.php
@@ -57,6 +57,8 @@ class RegisteredUserController extends Controller
Auth::login($user);
+ $request->session()->forget('pending_invite_id');
+
if ($redirect = $request->input('redirect')) {
if (str_starts_with($redirect, '/') && ! str_starts_with($redirect, '//')) {
return redirect($redirect);
diff --git a/app/Http/Middleware/App/EnsureRegistrationEnabled.php b/app/Http/Middleware/App/EnsureRegistrationEnabled.php
new file mode 100644
index 000000000..82d04c4c2
--- /dev/null
+++ b/app/Http/Middleware/App/EnsureRegistrationEnabled.php
@@ -0,0 +1,27 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Http\Middleware\App;
+
+use Closure;
+use Illuminate\Http\Request;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
+
+class EnsureRegistrationEnabled
+{
+ public function handle(Request $request, Closure $next): mixed
+ {
+ if (! config('trypost.self_hosted')) {
+ return $next($request);
+ }
+
+ if ($inviteId = $request->query('invite') ?? $request->session()->get('pending_invite_id')) {
+ $request->session()->put('pending_invite_id', $inviteId);
+
+ return $next($request);
+ }
+
+ throw new NotFoundHttpException;
+ }
+}
diff --git a/bootstrap/app.php b/bootstrap/app.php
index 12e6c57cb..03691e8c5 100644
--- a/bootstrap/app.php
+++ b/bootstrap/app.php
@@ -1,6 +1,7 @@
<?php
use App\Http\Middleware\Api\LoadWorkspaceFromToken;
+use App\Http\Middleware\App\EnsureRegistrationEnabled;
use App\Http\Middleware\App\HandleInertiaRequests;
use App\Http\Middleware\App\SetLocale;
use Illuminate\Foundation\Application;
@@ -32,6 +33,7 @@ return Application::configure(basePath: dirname(__DIR__))
$middleware->alias([
'workspace.token' => LoadWorkspaceFromToken::class,
+ 'registration.enabled' => EnsureRegistrationEnabled::class,
]);
$middleware->preventRequestForgery(except: [
diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php
new file mode 100644
index 000000000..a3a28b5d5
--- /dev/null
+++ b/database/seeders/UserSeeder.php
@@ -0,0 +1,36 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Database\Seeders;
+
+use App\Actions\User\CreateUser;
+use App\Actions\Workspace\CreateWorkspace;
+use App\Models\User;
+use Illuminate\Database\Seeder;
+
+class UserSeeder extends Seeder
+{
+ public function run(): void
+ {
+ if (User::query()->exists()) {
+ $this->command->info('UserSeeder: a user already exists, skipping.');
+
+ return;
+ }
+
+ $user = CreateUser::execute([
+ 'name' => 'Admin',
+ 'email' => '[email protected]',
+ 'password' => 'password',
+ 'email_verified_at' => now(),
+ 'timezone' => 'UTC',
+ ]);
+
+ CreateWorkspace::execute($user, ['name' => 'My Workspace']);
+
+ $this->command->info('Admin account created — change the password on first login:');
+ $this->command->line(' email: [email protected]');
+ $this->command->line(' password: password');
+ }
+}
diff --git a/resources/js/pages/auth/AcceptInvite.vue b/resources/js/pages/auth/AcceptInvite.vue
index 278ee462c..d168ef32a 100644
--- a/resources/js/pages/auth/AcceptInvite.vue
+++ b/resources/js/pages/auth/AcceptInvite.vue
@@ -96,7 +96,7 @@ const inviteUrl = computed(() => `/invites/${props.invite.id}`);
</Link>
</Button>
<Button as-child variant="outline" size="lg" class="w-full">
- <Link :href="register({ query: { redirect: inviteUrl, email: invite.email } })">
+ <Link :href="register({ query: { redirect: inviteUrl, email: invite.email, invite: invite.id } })">
{{ $t('auth.accept_invite.create_account') }}
</Link>
</Button>
diff --git a/resources/js/pages/auth/Login.vue b/resources/js/pages/auth/Login.vue
index 6a3376f7c..3b25e1d99 100644
--- a/resources/js/pages/auth/Login.vue
+++ b/resources/js/pages/auth/Login.vue
@@ -1,5 +1,6 @@
<script setup lang="ts">
-import { Form, Head } from '@inertiajs/vue3';
+import { Form, Head, usePage } from '@inertiajs/vue3';
+import { computed } from 'vue';
import SocialLogin from '@/components/auth/SocialLogin.vue';
import InputError from '@/components/InputError.vue';
@@ -19,6 +20,9 @@ defineProps<{
email?: string | null;
redirect?: string | null;
}>();
+
+const page = usePage();
+const isSelfHosted = computed(() => Boolean(page.props.selfHosted));
</script>
<template>
@@ -69,7 +73,7 @@ defineProps<{
</Button>
</div>
- <div class="text-center text-sm text-muted-foreground">
+ <div v-if="!isSelfHosted" class="text-center text-sm text-muted-foreground">
{{ $t('auth.login.no_account') }}
<TextLink :href="register()" :tabindex="5">{{ $t('auth.login.sign_up') }}</TextLink>
</div>
diff --git a/routes/auth.php b/routes/auth.php
index da4e5de02..f50f4a3a0 100644
--- a/routes/auth.php
+++ b/routes/auth.php
@@ -18,8 +18,10 @@ use Illuminate\Support\Facades\Route;
Route::get('/invites/{invite}', [AcceptInviteController::class, 'show'])->name('app.invites.show');
Route::middleware(['guest'])->group(function () {
- Route::get('/register', [RegisteredUserController::class, 'create'])->name('register');
- Route::post('/register', [RegisteredUserController::class, 'store'])->name('register.store');
+ Route::middleware('registration.enabled')->group(function () {
+ Route::get('/register', [RegisteredUserController::class, 'create'])->name('register');
+ Route::post('/register', [RegisteredUserController::class, 'store'])->name('register.store');
+ });
Route::get('/login', [AuthenticatedSessionController::class, 'create'])->name('login');
Route::post('/login', [AuthenticatedSessionController::class, 'store'])->name('login.store');
diff --git a/tests/Feature/AcceptInviteControllerTest.php b/tests/Feature/AcceptInviteControllerTest.php
index 6ad786d11..6d78840d0 100644
--- a/tests/Feature/AcceptInviteControllerTest.php
+++ b/tests/Feature/AcceptInviteControllerTest.php
@@ -19,7 +19,9 @@ beforeEach(function () {
]);
});
-test('show invite displays invite details for guest', function () {
+test('show invite displays invite details for guest when not self_hosted', function () {
+ config()->set('trypost.self_hosted', false);
+
$invite = Invite::factory()->create([
'account_id' => $this->account->id,
'invited_by' => $this->owner->id,
@@ -39,6 +41,26 @@ test('show invite displays invite details for guest', function () {
);
});
+test('show invite displays invite details for guest when self_hosted (page renders, gate happens on /register)', function () {
+ config()->set('trypost.self_hosted', true);
+
+ $invite = Invite::factory()->create([
+ 'account_id' => $this->account->id,
+ 'invited_by' => $this->owner->id,
+ 'email' => '[email protected]',
+ 'workspaces' => [$this->workspace->id],
+ ]);
+
+ $response = $this->get(route('app.invites.show', $invite));
+
+ $response->assertOk();
+ $response->assertInertia(fn ($page) => $page
+ ->component('auth/AcceptInvite', false)
+ ->has('invite')
+ ->where('invite.id', $invite->id)
+ );
+});
+
test('show invite displays invite details for authenticated user', function () {
$user = User::factory()->create([
'email' => '[email protected]',
diff --git a/tests/Feature/Auth/RegistrationTest.php b/tests/Feature/Auth/RegistrationTest.php
index 7382ce132..466a40d2c 100644
--- a/tests/Feature/Auth/RegistrationTest.php
+++ b/tests/Feature/Auth/RegistrationTest.php
@@ -4,6 +4,8 @@ declare(strict_types=1);
use App\Models\User;
+beforeEach(fn () => config()->set('trypost.self_hosted', false));
+
test('registration screen can be rendered', function () {
$response = $this->get(route('register'));
@@ -111,3 +113,74 @@ test('new users registering via invite have verified email automatically', funct
expect($user->email_verified_at)->not->toBeNull();
});
+
+test('register page returns 404 when self_hosted and no pending invite in session', function () {
+ config()->set('trypost.self_hosted', true);
+
+ $response = $this->get(route('register'));
+
+ $response->assertNotFound();
+});
+
+test('register POST returns 404 when self_hosted and no pending invite in session', function () {
+ config()->set('trypost.self_hosted', true);
+
+ $response = $this->post(route('register.store'), [
+ 'name' => 'Test User',
+ 'email' => '[email protected]',
+ 'password' => 'Password123!',
+ ]);
+
+ $response->assertNotFound();
+ expect(User::where('email', '[email protected]')->exists())->toBeFalse();
+});
+
+test('register page renders when self_hosted but session has pending invite', function () {
+ config()->set('trypost.self_hosted', true);
+
+ $response = $this
+ ->withSession(['pending_invite_id' => 'invite-abc'])
+ ->get(route('register'));
+
+ $response->assertOk();
+});
+
+test('register page renders when self_hosted with invite query param and persists it to session', function () {
+ config()->set('trypost.self_hosted', true);
+
+ $response = $this->get(route('register', ['invite' => 'invite-xyz']));
+
+ $response->assertOk();
+ $response->assertSessionHas('pending_invite_id', 'invite-xyz');
+});
+
+test('signup clears pending_invite_id from session', function () {
+ config()->set('trypost.self_hosted', true);
+
+ $this->withSession(['pending_invite_id' => 'invite-abc'])
+ ->post(route('register.store'), [
+ 'name' => 'Invitee',
+ 'email' => '[email protected]',
+ 'password' => 'Password123!',
+ ]);
+
+ expect(session('pending_invite_id'))->toBeNull();
+ expect(User::where('email', '[email protected]')->exists())->toBeTrue();
+});
+
+test('register works normally when not self_hosted even with pending invite in session', function () {
+ config()->set('trypost.self_hosted', false);
+
+ $response = $this
+ ->withSession(['pending_invite_id' => 'invite-abc'])
+ ->post(route('register.store'), [
+ 'name' => 'Invitee',
+ 'email' => '[email protected]',
+ 'password' => 'Password123!',
+ ]);
+
+ $response->assertSessionHasNoErrors();
+ expect(User::where('email', '[email protected]')->exists())->toBeTrue();
+ // Cleared regardless of mode, since signup consumes the marker.
+ expect(session('pending_invite_id'))->toBeNull();
+});
diff --git a/tests/Feature/Auth/SignupUtmTrackingTest.php b/tests/Feature/Auth/SignupUtmTrackingTest.php
index ab346071a..9a80e10e3 100644
--- a/tests/Feature/Auth/SignupUtmTrackingTest.php
+++ b/tests/Feature/Auth/SignupUtmTrackingTest.php
@@ -6,6 +6,8 @@ use App\Models\User;
use Laravel\Socialite\Facades\Socialite;
use Laravel\Socialite\Two\User as SocialiteUser;
+beforeEach(fn () => config()->set('trypost.self_hosted', false));
+
test('email registration saves utm parameters from the register page query string', function () {
$utms = [
'utm_source' => 'peerlist',
diff --git a/tests/Feature/GitHubAuthToggleTest.php b/tests/Feature/GitHubAuthToggleTest.php
index 8d24829f0..4defbd5b6 100644
--- a/tests/Feature/GitHubAuthToggleTest.php
+++ b/tests/Feature/GitHubAuthToggleTest.php
@@ -2,6 +2,8 @@
declare(strict_types=1);
+beforeEach(fn () => config()->set('trypost.self_hosted', false));
+
test('login page shares github auth enabled prop as false when disabled', function () {
config(['trypost.github_auth_enabled' => false]);
@@ -52,3 +54,16 @@ test('github auth callback route exists', function () {
// Should redirect to login on failure (no OAuth code), not 404
$response->assertRedirect(route('login'));
});
+
+test('register page still shares github auth enabled prop when self_hosted (via pending invite)', function () {
+ config()->set('trypost.self_hosted', true);
+ config()->set('trypost.github_auth_enabled', true);
+
+ $response = $this
+ ->withSession(['pending_invite_id' => 'invite-abc'])
+ ->get(route('register'));
+
+ $response->assertOk();
+ $page = $response->original->getData()['page'];
+ expect($page['props']['githubAuthEnabled'])->toBeTrue();
+});
diff --git a/tests/Feature/GoogleAuthToggleTest.php b/tests/Feature/GoogleAuthToggleTest.php
index bb01975e7..05b42d13f 100644
--- a/tests/Feature/GoogleAuthToggleTest.php
+++ b/tests/Feature/GoogleAuthToggleTest.php
@@ -2,6 +2,8 @@
declare(strict_types=1);
+beforeEach(fn () => config()->set('trypost.self_hosted', false));
+
test('login page loads when google auth is disabled', function () {
config(['trypost.google_auth_enabled' => false]);
@@ -69,3 +71,16 @@ test('google auth callback route exists', function () {
// Should redirect to login on failure (no OAuth code), not 404
$response->assertRedirect(route('login'));
});
+
+test('register page still shares google auth enabled prop when self_hosted (via pending invite)', function () {
+ config()->set('trypost.self_hosted', true);
+ config()->set('trypost.google_auth_enabled', true);
+
+ $response = $this
+ ->withSession(['pending_invite_id' => 'invite-abc'])
+ ->get(route('register'));
+
+ $response->assertOk();
+ $page = $response->original->getData()['page'];
+ expect($page['props']['googleAuthEnabled'])->toBeTrue();
+});