9.6 KiB
Nextcloud OAuth Authentication Setup Guide
This guide explains how to set up Nextcloud OAuth authentication for United Tattoo Studio and migrate existing artist accounts.
Table of Contents
- Nextcloud OAuth App Registration
- Environment Configuration
- Nextcloud Group Setup
- Migrating Existing Artists
- Testing the Integration
- Troubleshooting
Nextcloud OAuth App Registration
Step 1: Access OAuth Settings in Nextcloud
- Log in to your Nextcloud instance as an administrator: https://portal.united-tattoos.com
- Navigate to Settings → Security → OAuth 2.0 clients (bottom of the page)
Step 2: Create New OAuth App
- Click "Add client"
- Fill in the following details:
- Name:
United Tattoo Studio(or any descriptive name) - Redirection URI:
https://united-tattoos.com/api/auth/callback/nextcloud- For local development:
http://localhost:3000/api/auth/callback/nextcloud - For preview/staging:
https://your-preview-url.pages.dev/api/auth/callback/nextcloud
- For local development:
- Name:
- Click "Add"
Step 3: Save Credentials
After creating the OAuth app, Nextcloud will display:
- Client Identifier (Client ID)
- Secret (Client Secret)
IMPORTANT: Copy these values immediately and store them securely. The secret will not be shown again.
Environment Configuration
Step 1: Update Environment Variables
Add the following variables to your .env.local file (or production environment):
# Nextcloud Configuration
NEXTCLOUD_BASE_URL="https://portal.united-tattoos.com"
# Nextcloud OAuth Authentication
NEXTCLOUD_OAUTH_CLIENT_ID="your-client-id-from-step-3"
NEXTCLOUD_OAUTH_CLIENT_SECRET="your-client-secret-from-step-3"
# Group names for auto-provisioning (customize if needed)
NEXTCLOUD_ARTISTS_GROUP="artists"
NEXTCLOUD_ADMINS_GROUP="shop_admins"
# Nextcloud CalDAV Integration (existing, for calendar sync)
NEXTCLOUD_USERNAME="your-service-account-username"
NEXTCLOUD_PASSWORD="your-service-account-app-password"
NEXTCLOUD_CALENDAR_BASE_PATH="/remote.php/dav/calendars"
Step 2: Verify Configuration
Run the following command to check for configuration errors:
npm run build
If there are missing environment variables, the build will fail with a helpful error message from lib/env.ts.
Nextcloud Group Setup
Step 1: Create Required Groups
- In Nextcloud, navigate to Settings → Users
- Click "Add group" and create the following groups:
artists- For tattoo artists who need access to their portfoliosshop_admins- For shop administrators
Step 2: Assign Users to Groups
For each existing artist or admin:
- Go to Settings → Users
- Find the user in the list
- Click on their row and select the appropriate group(s):
- Artists: Add to
artistsgroup - Shop admins: Add to
shop_adminsgroup - Super admins: Add to both
shop_adminsANDadmins(oradmin) group
- Artists: Add to
Note: Users can be in multiple groups. For example, a shop owner who is also an artist should be in both artists and shop_admins.
Migrating Existing Artists
Understanding the Migration
When an artist signs in via Nextcloud OAuth for the first time:
- The system checks if a user with that email already exists in the database
- If user exists: The existing user account is linked to the Nextcloud OAuth session
- If user doesn't exist: A new user and artist profile are auto-created based on Nextcloud group membership
Step 1: Match Email Addresses
Ensure that each artist's email in Nextcloud matches their email in the United Tattoo database:
-- Query to check existing artist emails in D1 database
SELECT u.email, a.name, a.slug
FROM users u
JOIN artists a ON u.id = a.user_id
WHERE u.role = 'ARTIST';
Run this via:
wrangler d1 execute united-tattoo --command="SELECT u.email, a.name, a.slug FROM users u JOIN artists a ON u.id = a.user_id WHERE u.role = 'ARTIST';"
Step 2: Create Nextcloud Accounts (If Needed)
If an artist doesn't have a Nextcloud account yet:
- Go to Settings → Users in Nextcloud
- Click "New user"
- Fill in:
- Username: Artist's preferred username (e.g.,
amari.kyss) - Display name: Artist's full name (e.g., "Amari Kyss")
- Email: Must match the email in the database
- Groups: Add to
artistsgroup
- Username: Artist's preferred username (e.g.,
- Set a temporary password and send it to the artist
- Ask the artist to change their password on first login
Step 3: Notify Artists
Send an email to all artists with the following information:
Email Template:
Subject: New Login Process for United Tattoo Studio Dashboard
Hello [Artist Name],
We've updated the artist dashboard login process to use your Nextcloud account for easier access.
What's Changed:
- You now sign in using your Nextcloud credentials (same account you use for [calendar/files/etc])
- No need to remember a separate password for the artist dashboard
- More secure authentication via OAuth
How to Sign In:
1. Go to https://united-tattoos.com/auth/signin
2. Click "Sign in with Nextcloud"
3. Use your Nextcloud username and password
4. You'll be redirected to your artist dashboard
Your Nextcloud Credentials:
- Username: [their Nextcloud username]
- Email: [their email]
- If you forgot your Nextcloud password, you can reset it at: https://portal.united-tattoos.com/login
Need Help?
Contact [admin contact] if you have any issues signing in.
Thanks,
United Tattoo Studio Team
Testing the Integration
Test 1: New Artist Sign In
- Ensure a test user is in the
artistsgroup in Nextcloud - Go to
/auth/signinon your website - Click "Sign in with Nextcloud"
- Authorize the OAuth app
- Verify:
- User is created in the
userstable - Artist profile is created in the
artiststable - Redirect to
/artist-dashboardworks - Artist can view/edit their profile
- User is created in the
Test 2: Existing Artist Sign In
- Use an artist whose email matches an existing database record
- Follow the same sign-in process
- Verify:
- No duplicate user/artist created
- Existing artist profile is accessible
- Portfolio images are preserved
Test 3: Admin Sign In
- Ensure a test user is in the
shop_adminsgroup - Sign in via Nextcloud OAuth
- Verify:
- User is created with
SHOP_ADMINrole - Redirect to
/admindashboard works - Admin can access all admin features
- User is created with
Test 4: Unauthorized User
- Create a Nextcloud user NOT in any authorized group
- Attempt to sign in via OAuth
- Verify:
- Sign-in is rejected with an error message
- User is not created in the database
- Error message suggests joining the 'artists' or 'shop_admins' group
Test 5: Admin Fallback (Emergency Access)
- Go to
/auth/signin?admin=true - Verify the credentials form is shown
- Sign in with
nicholai@biohazardvfx.com(or any email in dev mode) - Verify admin access works
Troubleshooting
Issue: "Unable to sign in with Nextcloud"
Possible causes:
- User not in
artistsorshop_adminsgroup - OAuth app not configured correctly in Nextcloud
- Redirect URI mismatch
Solution:
- Check user's group membership in Nextcloud
- Verify
NEXTCLOUD_OAUTH_CLIENT_IDandNEXTCLOUD_OAUTH_CLIENT_SECRETare correct - Ensure redirect URI in Nextcloud matches your domain exactly
Issue: "Nextcloud API error" in server logs
Possible causes:
- Service account credentials (
NEXTCLOUD_USERNAME/NEXTCLOUD_PASSWORD) are incorrect - Nextcloud OCS API is not accessible
Solution:
- Test service account credentials manually:
curl -u "username:password" https://portal.united-tattoos.com/ocs/v1.php/cloud/users/testuser - Ensure the service account has admin privileges in Nextcloud
- Check Nextcloud logs for any API access errors
Issue: Duplicate artist profiles created
Possible causes:
- Email mismatch between Nextcloud and database
- User signed in before email was matched
Solution:
-
Identify duplicate records:
SELECT * FROM artists WHERE user_id IN ( SELECT user_id FROM artists GROUP BY user_id HAVING COUNT(*) > 1 ); -
Manually merge duplicates by updating portfolio images to point to the correct artist
-
Delete the duplicate artist profile
Issue: Artist can't access dashboard after sign-in
Possible causes:
- Artist profile not created during auto-provisioning
- Database transaction failed
Solution:
-
Check if user exists:
SELECT * FROM users WHERE email = 'artist@example.com'; -
Check if artist profile exists:
SELECT * FROM artists WHERE user_id = 'user-id-from-above'; -
If user exists but artist doesn't, manually create artist:
INSERT INTO artists (id, user_id, name, bio, specialties, is_active, slug) VALUES ('uuid', 'user-id', 'Artist Name', '', '[]', 1, 'artist-name');
Next Steps
After completing this setup:
- Monitor sign-ins: Check server logs for any authentication errors
- Gather feedback: Ask artists about their experience with the new login process
- Update documentation: Keep this guide updated with any changes to the process
- Consider enhancements:
- Sync artist profile photos from Nextcloud
- Enable calendar integration for all artists
- Add two-factor authentication requirement
Support
For technical support or questions about this integration, contact the development team or file an issue in the project repository.
Last updated: 2025-10-22