Skip to content

Commit

Permalink
PR comments #2
Browse files Browse the repository at this point in the history
  • Loading branch information
infomiho committed Aug 22, 2024
1 parent a7e8493 commit 6fbeeda
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 34 deletions.
9 changes: 4 additions & 5 deletions waspc/data/Generator/templates/sdk/wasp/server/auth/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { Request as ExpressRequest } from 'express'
import { type ProviderId, createUser, findAuthWithUserBy } from '../../auth/utils.js'
import { prisma } from '../index.js'
import { Expand } from '../../universal/types.js'
import { ProviderName } from '../_types/index.js';

// PUBLIC API
export type OnBeforeSignupHook = (
Expand Down Expand Up @@ -71,7 +70,7 @@ type OnAfterSignupHookParams = {
* OAuth flow data that was generated during the OAuth flow. This is only
* available if the user signed up using OAuth.
*/
oauth?: OAuthParams
oauth?: OAuthData
/**
* Request object that can be used to access the incoming request.
*/
Expand All @@ -86,7 +85,7 @@ type OnBeforeOAuthRedirectHookParams = {
/**
* Unique request ID that was generated during the OAuth flow.
*/
uniqueRequestId: OAuthParams['uniqueRequestId']
oauth: Pick<OAuthData, 'uniqueRequestId'>
/**
* Request object that can be used to access the incoming request.
*/
Expand Down Expand Up @@ -117,15 +116,15 @@ type OnAfterLoginHookParams = {
* OAuth flow data that was generated during the OAuth flow. This is only
* available if the user logged in using OAuth.
*/
oauth?: OAuthParams
oauth?: OAuthData
/**
* Request object that can be used to access the incoming request.
*/
req: ExpressRequest
} & InternalAuthHookParams

// PRIVATE API (server)
export type OAuthParams = {
export type OAuthData = {
/**
* Unique request ID that was generated during the OAuth flow.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type {
OnBeforeLoginHook,
OnAfterLoginHook,
InternalAuthHookParams,
OAuthParams,
OAuthData,
} from './hooks.js'

{=# isExternalAuthEnabled =}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import {
loginPath,
handleOAuthErrorAndGetRedirectUri,
} from 'wasp/server/auth'
import { OAuthParams } from 'wasp/server/auth'
import { OAuthData } from 'wasp/server/auth'
import { onBeforeOAuthRedirectHook } from '../../hooks.js'

export function createOAuthProviderRouter<OT extends OAuthType, Tokens extends OAuthParams['tokens'] = never>({
export function createOAuthProviderRouter<OT extends OAuthType, Tokens extends OAuthData['tokens'] = never>({
provider,
oAuthType,
userSignupFields,
Expand Down Expand Up @@ -75,7 +75,7 @@ export function createOAuthProviderRouter<OT extends OAuthType, Tokens extends O
const { url: redirectUrlAfterHook } = await onBeforeOAuthRedirectHook({
req,
url: redirectUrl,
uniqueRequestId: oAuthState.state,
oauth: { uniqueRequestId: oAuthState.state }
})
return redirect(res, redirectUrlAfterHook.toString())
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { type {= authEntityUpper =} } from 'wasp/entities'
import { prisma } from 'wasp/server'
import { type UserSignupFields, type ProviderConfig } from 'wasp/auth/providers/types'
import { type OAuthParams } from 'wasp/server/auth'
import { type OAuthData } from 'wasp/server/auth'
import { getRedirectUriForOneTimeCode, tokenStore } from 'wasp/server/auth'
import {
onBeforeSignupHook,
Expand All @@ -33,7 +33,7 @@ export async function finishOAuthFlowAndGetRedirectUri({
providerUserId: string;
userSignupFields: UserSignupFields | undefined;
req: ExpressRequest;
oauth: OAuthParams;
oauth: OAuthData;
}): Promise<URL> {
const providerId = createProviderId(provider.id, providerUserId);

Expand Down Expand Up @@ -63,7 +63,7 @@ async function getAuthIdFromProviderDetails({
providerProfile: any;
userSignupFields: UserSignupFields | undefined;
req: ExpressRequest;
oauth: OAuthParams;
oauth: OAuthData;
}): Promise<{= authEntityUpper =}['id']> {
const existingAuthIdentity = await prisma.{= authIdentityEntityLower =}.findUnique({
where: {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion waspc/examples/todoApp/src/auth/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const onBeforeOAuthRedirect: OnBeforeOAuthRedirectHook = async (
log('query params before oAuth redirect', args.req.query)

// Saving query params for later use in onAfterSignup hook
const id = args.uniqueRequestId
const id = args.oauth.uniqueRequestId
oAuthQueryStore.set(id, args.req.query)

return { url: args.url }
Expand Down

0 comments on commit 6fbeeda

Please sign in to comment.