-
Notifications
You must be signed in to change notification settings - Fork 0
add social login to auth #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,12 @@ | ||
| import { logout, user } from '@holo-js/auth' | ||
|
|
||
| export async function POST() { | ||
| const signedOut = await logout() | ||
| const headers = new Headers() | ||
| for (const cookie of signedOut.cookies) { | ||
| headers.append('set-cookie', cookie) | ||
| } | ||
| await logout() | ||
|
|
||
| return Response.json({ | ||
| ok: true, | ||
| authenticated: false, | ||
| message: 'Signed out successfully.', | ||
| user: await user(), | ||
| }, { | ||
| headers, | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { redirect } from 'next/navigation' | ||
| import auth from '@holo-js/auth' | ||
| import { callback } from '@holo-js/auth-social' | ||
|
|
||
| export function GET(request: Request): Promise<Response> { | ||
| return handleCallback(request) | ||
| } | ||
|
|
||
| async function handleCallback(request: Request): Promise<Response> { | ||
| const result = await callback('github', request) | ||
| if (!result.ok) { | ||
| return Response.json({ | ||
| message: result.message, | ||
| }, { | ||
| status: result.status, | ||
| }) | ||
| } | ||
|
|
||
| await auth.guard(result.guard).loginUsing(result.user) | ||
| redirect('/admin') | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { redirect } from '@holo-js/auth-social' | ||
|
|
||
| export function GET(request: Request): Promise<Response> { | ||
| return redirect('github', request) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { redirect } from 'next/navigation' | ||
| import auth from '@holo-js/auth' | ||
| import { callback } from '@holo-js/auth-social' | ||
|
|
||
| export function GET(request: Request): Promise<Response> { | ||
| return handleCallback(request) | ||
| } | ||
|
|
||
| async function handleCallback(request: Request): Promise<Response> { | ||
| const result = await callback('google', request) | ||
| if (!result.ok) { | ||
| return Response.json({ | ||
| message: result.message, | ||
| }, { | ||
| status: result.status, | ||
| }) | ||
| } | ||
|
|
||
| await auth.guard(result.guard).loginUsing(result.user) | ||
| redirect('/admin') | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { redirect } from '@holo-js/auth-social' | ||
|
|
||
| export function GET(request: Request): Promise<Response> { | ||
| return redirect('google', request) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { getHeaders, getRequestURL, type H3Event } from 'h3' | ||
|
|
||
| export function toWebRequest(event: H3Event): Request { | ||
| const headers = new Headers() | ||
| for (const [key, value] of Object.entries(getHeaders(event))) { | ||
| if (typeof value === 'string') { | ||
| headers.set(key, value) | ||
| } | ||
| } | ||
|
|
||
| return new Request(getRequestURL(event), { | ||
| method: event.method, | ||
| headers, | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { redirect } from '@holo-js/auth-social' | ||
|
|
||
| import { toWebRequest } from '../../lib/request' | ||
|
|
||
| export default defineEventHandler((event) => { | ||
| return redirect('github', toWebRequest(event)) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import auth from '@holo-js/auth' | ||
| import { callback } from '@holo-js/auth-social' | ||
|
|
||
| import { toWebRequest } from '../../../lib/request' | ||
|
|
||
| export default defineEventHandler(async (event) => { | ||
| const result = await callback('github', toWebRequest(event)) | ||
| if (!result.ok) { | ||
| setResponseStatus(event, result.status) | ||
| return { message: result.message } | ||
| } | ||
|
|
||
| await auth.guard(result.guard).loginUsing(result.user) | ||
| return sendRedirect(event, '/admin', 303) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { redirect } from '@holo-js/auth-social' | ||
|
|
||
| import { toWebRequest } from '../../lib/request' | ||
|
|
||
| export default defineEventHandler((event) => { | ||
| return redirect('google', toWebRequest(event)) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import auth from '@holo-js/auth' | ||
| import { callback } from '@holo-js/auth-social' | ||
|
|
||
| import { toWebRequest } from '../../../lib/request' | ||
|
|
||
| export default defineEventHandler(async (event) => { | ||
| const result = await callback('google', toWebRequest(event)) | ||
| if (!result.ok) { | ||
| setResponseStatus(event, result.status) | ||
| return { message: result.message } | ||
| } | ||
|
|
||
| await auth.guard(result.guard).loginUsing(result.user) | ||
| return sendRedirect(event, '/admin', 303) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { redirect } from '@holo-js/auth-social' | ||
|
|
||
| export function GET({ request }: { request: Request }): Promise<Response> { | ||
| return redirect('github', request) | ||
| } |
21 changes: 21 additions & 0 deletions
21
apps/blog-sveltekit/src/routes/auth/github/callback/+server.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { json, redirect } from '@sveltejs/kit' | ||
| import auth from '@holo-js/auth' | ||
| import { callback } from '@holo-js/auth-social' | ||
|
|
||
| export function GET({ request }: { request: Request }): Promise<Response> { | ||
| return handleCallback(request) | ||
| } | ||
|
|
||
| async function handleCallback(request: Request): Promise<Response> { | ||
| const result = await callback('github', request) | ||
| if (!result.ok) { | ||
| return json({ | ||
| message: result.message, | ||
| }, { | ||
| status: result.status, | ||
| }) | ||
| } | ||
|
|
||
| await auth.guard(result.guard).loginUsing(result.user) | ||
| throw redirect(303, '/admin') | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { redirect } from '@holo-js/auth-social' | ||
|
|
||
| export function GET({ request }: { request: Request }): Promise<Response> { | ||
| return redirect('google', request) | ||
| } |
21 changes: 21 additions & 0 deletions
21
apps/blog-sveltekit/src/routes/auth/google/callback/+server.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { json, redirect } from '@sveltejs/kit' | ||
| import auth from '@holo-js/auth' | ||
| import { callback } from '@holo-js/auth-social' | ||
|
|
||
| export function GET({ request }: { request: Request }): Promise<Response> { | ||
| return handleCallback(request) | ||
| } | ||
|
|
||
| async function handleCallback(request: Request): Promise<Response> { | ||
| const result = await callback('google', request) | ||
| if (!result.ok) { | ||
| return json({ | ||
| message: result.message, | ||
| }, { | ||
| status: result.status, | ||
| }) | ||
| } | ||
|
|
||
| await auth.guard(result.guard).loginUsing(result.user) | ||
| throw redirect(303, '/admin') | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: cobraprojects/holo-js
Length of output: 409
🏁 Script executed:
Repository: cobraprojects/holo-js
Length of output: 488
🏁 Script executed:
Repository: cobraprojects/holo-js
Length of output: 191
🏁 Script executed:
Repository: cobraprojects/holo-js
Length of output: 753
🏁 Script executed:
# Read the guestOnly and authOnly implementations cat packages/auth/src/sveltekit/server.tsRepository: cobraprojects/holo-js
Length of output: 6098
🏁 Script executed:
Repository: cobraprojects/holo-js
Length of output: 236
🏁 Script executed:
Repository: cobraprojects/holo-js
Length of output: 47
🏁 Script executed:
Repository: cobraprojects/holo-js
Length of output: 2259
🏁 Script executed:
Repository: cobraprojects/holo-js
Length of output: 708
🏁 Script executed:
# Read the adapter-sveltekit implementation cat packages/adapter-sveltekit/src/index.tsRepository: cobraprojects/holo-js
Length of output: 5695
🏁 Script executed:
# Read the actual callback handler to confirm the flow cat apps/blog-sveltekit/src/routes/auth/google/callback/+server.tsRepository: cobraprojects/holo-js
Length of output: 636
🏁 Script executed:
Repository: cobraprojects/holo-js
Length of output: 572
🏁 Script executed:
Repository: cobraprojects/holo-js
Length of output: 47
Add callback routes to
guestOnlyguard inhooks.server.ts.The
/auth/google/callbackand/auth/github/callbackroutes are not covered by theguestOnlyorauthOnlyhandlers in hooks.server.ts. This meansrunWithSvelteKitRequestEventis never called for these routes, so theAsyncLocalStoragecontext is not established. WhenloginUsing()callsappendResponseCookies(), the session cookie call reachesappendResponseCookiein the adapter, which silently returns without setting the cookie becausegetSvelteKitRequestEventStore().getStore()isundefined. The session is created server-side but the cookie is never sent to the client—the user is redirected to/adminbut arrives unauthenticated.Add both callback routes to the
guestOnlyroutes list (or wrap the handler withrunWithSvelteKitRequestEventif they should be auth-required):🤖 Prompt for AI Agents