The canonical /login and /register already offered GitHub OAuth, but the
legacy /auth screen (reached via router.push('/auth') from insights, drafts,
creator-studio, follow-requests) was email/password only — a GitHub-native
new user landing there had no way in. Add a guarded "Sign in with GitHub"
button that calls githubService.connectGitHub() (redirects to GitHub's
authorize endpoint; /auth/github/callback, already in middleware publicPaths,
completes it). Also drop the emoji from the footer copy per the no-emoji UI
rule while editing this screen.
Test: connectGitHub redirects to the authorize endpoint with the configured
client_id, callback redirect_uri, and user:email,repo,read:user scopes.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
41 lines
1.6 KiB
TypeScript
41 lines
1.6 KiB
TypeScript
/// <reference types="vitest/globals" />
|
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
import { githubService } from '@/services/githubService'
|
|
|
|
/**
|
|
* connectGitHub is the "Sign in with GitHub" entry point surfaced on the login
|
|
* screens. It must redirect to GitHub's OAuth authorize endpoint with the
|
|
* client id, the callback redirect URI, and the scopes the backend needs to
|
|
* write back stars/follows and read the user's email.
|
|
*/
|
|
describe('githubService.connectGitHub', () => {
|
|
const originalLocation = window.location
|
|
const originalClientId = process.env.NEXT_PUBLIC_GITHUB_CLIENT_ID
|
|
|
|
beforeEach(() => {
|
|
Object.defineProperty(window, 'location', {
|
|
configurable: true,
|
|
value: { origin: 'https://app.gitgram.com', href: '' },
|
|
})
|
|
process.env.NEXT_PUBLIC_GITHUB_CLIENT_ID = 'test-client-123'
|
|
})
|
|
|
|
afterEach(() => {
|
|
Object.defineProperty(window, 'location', { configurable: true, value: originalLocation })
|
|
process.env.NEXT_PUBLIC_GITHUB_CLIENT_ID = originalClientId
|
|
})
|
|
|
|
it('redirects to the GitHub authorize endpoint', () => {
|
|
githubService.connectGitHub()
|
|
expect(window.location.href).toContain('https://github.com/login/oauth/authorize')
|
|
})
|
|
|
|
it('includes the configured client id, callback redirect, and scopes', () => {
|
|
githubService.connectGitHub()
|
|
const url = new URL(window.location.href)
|
|
expect(url.searchParams.get('client_id')).toBe('test-client-123')
|
|
expect(url.searchParams.get('redirect_uri')).toBe('https://app.gitgram.com/auth/github/callback')
|
|
expect(url.searchParams.get('scope')).toBe('user:email,repo,read:user')
|
|
})
|
|
})
|