-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2567 from ever-co/develop
Release
- Loading branch information
Showing
14 changed files
with
235 additions
and
127 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 { validateForm } from '@app/helpers/validations'; | ||
import { signWithSocialLoginsRequest } from '@app/services/server/requests'; | ||
import { ProviderEnum } from '@app/services/server/requests/OAuth'; | ||
|
||
import { NextResponse } from 'next/server'; | ||
|
||
export async function POST(req: Request) { | ||
const body = (await req.json()) as { email: string; password: string }; | ||
const body = (await req.json()) as { provider: ProviderEnum; access_token: string }; | ||
|
||
const { errors, isValid } = validateForm(['email'], body); | ||
|
||
if (!isValid) { | ||
return NextResponse.json({ errors }, { status: 400 }); | ||
} | ||
|
||
const { data } = await signWithSocialLoginsRequest(body.email); | ||
const { data } = await signWithSocialLoginsRequest(body.provider, body.access_token); | ||
|
||
return NextResponse.json(data); | ||
} |
This file contains 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 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 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,83 @@ | ||
import { type Adapter } from '@auth/core/adapters'; | ||
import { signWithSocialLoginsRequest } from '@app/services/server/requests'; | ||
import { getUserOrganizationsRequest, signInWorkspaceAPI } from '@app/services/client/api/auth/invite-accept'; | ||
|
||
export enum ProviderEnum { | ||
GITHUB = 'github', | ||
GOOGLE = 'google', | ||
FACEBOOK = 'facebook', | ||
TWITTER = 'twitter' | ||
} | ||
|
||
export const GauzyAdapter: Adapter = { | ||
// Provide createUser and other related functions that will call Gauzy APIs when implementing social signup | ||
}; | ||
|
||
async function signIn(provider: ProviderEnum, access_token: string) { | ||
try { | ||
const gauzyUser = await signWithSocialLoginsRequest(provider, access_token); | ||
|
||
if (!gauzyUser) { | ||
return Promise.reject({ | ||
errors: { | ||
email: 'Your account is not yet ready to be used on the Ever Teams Platform' | ||
} | ||
}); | ||
} | ||
|
||
const data = await signInWorkspaceAPI(gauzyUser?.data.confirmed_email, gauzyUser?.data.workspaces[0].token); | ||
const tenantId = data.user?.tenantId || ''; | ||
const token = data.token; | ||
const userId = data.user?.id; | ||
|
||
const { data: organizations } = await getUserOrganizationsRequest({ | ||
tenantId, | ||
userId, | ||
token | ||
}); | ||
|
||
const organization = organizations?.items[0]; | ||
|
||
if (!organization) { | ||
return Promise.reject({ | ||
errors: { | ||
email: 'Your account is not yet ready to be used on the Ever Teams Platform' | ||
} | ||
}); | ||
} | ||
return { data, gauzyUser, organization, tenantId, userId }; | ||
} catch (error) { | ||
throw new Error('Signin error', { cause: error }); | ||
} | ||
} | ||
|
||
export async function signInCallback(provider: ProviderEnum, access_token: string): Promise<boolean> { | ||
try { | ||
const { gauzyUser, organization } = await signIn(provider, access_token); | ||
return !!gauzyUser && !!organization; | ||
} catch (error) { | ||
return false; | ||
} | ||
} | ||
|
||
export async function jwtCallback(provider: ProviderEnum, access_token: string) { | ||
try { | ||
const { data, gauzyUser, organization, tenantId, userId } = await signIn(provider, access_token); | ||
return { | ||
access_token, | ||
refresh_token: { | ||
token: data.refresh_token | ||
}, | ||
teamId: gauzyUser?.data.workspaces[0].current_teams[0].team_id, | ||
tenantId, | ||
organizationId: organization?.organizationId, | ||
languageId: 'en', | ||
noTeamPopup: true, | ||
userId, | ||
workspaces: gauzyUser?.data.workspaces, | ||
confirmed_mail: gauzyUser?.data.confirmed_email | ||
}; | ||
} catch (error) { | ||
throw new Error('Signin error', { cause: error }); | ||
} | ||
} |
This file contains 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 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.