-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/connect-and-disconnect-oauth-provider #79
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
Open
AlexandrNel
wants to merge
6
commits into
dev
Choose a base branch
from
feature/connect-oauth
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d7195a0
refactor(auth): move reusable variables and components to entities, a…
AlexandrNel 833e62a
refactor: remove logic duplication for redirect, add QueryParamshandl…
AlexandrNel 76f8002
feature(profile): add redirect page, improve oauth redirect page by a…
AlexandrNel d9ab38d
feature(profile): add connect and disconnect OAuth provider feature o…
AlexandrNel b1505a7
refactor: move QueryParamshandler in AppProviders
AlexandrNel 115c8c5
refactor(auth): move mutation hooks to API layer, converte auth icons…
AlexandrNel 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { ProfilePage as default } from 'pages/profile/'; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,27 @@ | ||
| 'use client'; | ||
|
|
||
| import { type Route } from 'next'; | ||
| import { useRouter, useSearchParams } from 'next/navigation'; | ||
| import { useEffect, useRef } from 'react'; | ||
| import { toast } from 'sonner'; | ||
|
|
||
| export function QueryParamsHandler() { | ||
| const params = useSearchParams(); | ||
| const isShowToast = useRef(false); | ||
| const router = useRouter(); | ||
| useEffect(() => { | ||
| const success = params?.get('success'); | ||
| const message = params?.get('message'); | ||
|
|
||
| if (isShowToast.current || !success) return; | ||
|
|
||
| if (success === 'true' && message) { | ||
| toast.success(message); | ||
| } else if (success === 'false' && message) { | ||
| toast.error(message); | ||
| } | ||
| isShowToast.current = true; | ||
| router.replace(location.pathname as Route); | ||
| }, [params, router]); | ||
| return null; | ||
| } | ||
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,12 +1,20 @@ | ||
| import { queryOptions } from '@tanstack/react-query'; | ||
| import { AuthHttp } from './http'; | ||
| import { authKeys } from '../model/const'; | ||
|
|
||
| export class AuthQueries { | ||
| static getOAuthProviders() { | ||
| return queryOptions({ | ||
| queryKey: ['oauth-providers'], | ||
| queryKey: authKeys.availableProviders(), | ||
| queryFn: async ({ signal }) => AuthHttp.oAuthProviders(signal), | ||
| staleTime: 60_000 * 360 * 24, | ||
| }); | ||
| } | ||
| static getConnectedOAuthProviders() { | ||
| return queryOptions({ | ||
| queryKey: authKeys.connectedProviders(), | ||
| queryFn: async ({ signal }) => AuthHttp.connectedOAuthProviders(signal), | ||
| staleTime: 60_000 * 360 * 24, | ||
| }); | ||
| } | ||
| } |
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,6 +1,44 @@ | ||
| import { type TAuth } from 'entities/auth'; | ||
| import YandexIcon from 'public/yandex-logo.svg'; | ||
| import VkontakteIcon from 'public/vkontakte-logo.svg'; | ||
| import GoogleIcon from 'public/google-logo.svg'; | ||
| import GithubIcon from 'public/github-logo.svg'; | ||
|
|
||
| export const MIN_PASS_LENGTH = 8; | ||
| export const MAX_PASS_LENGTH = 32; | ||
| export const OTP_LENGTH = 6; | ||
|
|
||
| export const MIN_NAME_LENGTH = 2; | ||
| export const MAX_NAME_LENGTH = 50; | ||
|
|
||
| export type OAuthProviderMeta = { | ||
| label: string; | ||
| iconSrc: string; | ||
| buttonClassName?: string; | ||
| }; | ||
|
|
||
| export const OAUTH_PROVIDERS: Record<TAuth.OAuthProvider, OAuthProviderMeta> = { | ||
| yandex: { | ||
| label: 'Яндекс', | ||
| iconSrc: YandexIcon, | ||
| buttonClassName: 'text-[#fc3f1d] hover:text-[#fc3f1d]', | ||
| }, | ||
| vkontakte: { | ||
| label: 'Вконтакте', | ||
| iconSrc: VkontakteIcon, | ||
| buttonClassName: 'bg-[#07f] hover:bg-[#07f]', | ||
| }, | ||
| google: { label: 'Google', iconSrc: GoogleIcon }, | ||
| github: { | ||
| label: 'GitHub', | ||
| iconSrc: GithubIcon, | ||
| buttonClassName: 'bg-[#24292f] hover:bg-[#24292f] text-white hover:text-white ', | ||
| }, | ||
| } as const; | ||
| export const OAUTH_PROVIDERS_COUNT = Object.keys(OAUTH_PROVIDERS).length; | ||
|
|
||
| export const authKeys = { | ||
| all: ['auth'] as const, | ||
| availableProviders: () => [...authKeys.all, 'providers', 'available'] as const, | ||
| connectedProviders: () => [...authKeys.all, 'providers', 'connected'] as const, | ||
| }; |
This file was deleted.
Oops, something went wrong.
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,49 @@ | ||
| import type { ButtonHTMLAttributes } from 'react'; | ||
| import { Button } from 'shared/ui'; | ||
| import { cn } from 'shared/lib/utils'; | ||
| import { CAuth } from 'entities/auth'; | ||
| import type { TAuth } from 'entities/auth'; | ||
| import Link from 'next/link'; | ||
| import { type Route } from 'next'; | ||
| import Image from 'next/image'; | ||
|
|
||
| type OAuthButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children'> & { | ||
| provider: TAuth.OAuthProvider; | ||
| iconClassName?: string; | ||
| href: Route; | ||
| }; | ||
|
|
||
| export function OAuthButton({ | ||
| provider, | ||
| className, | ||
| iconClassName, | ||
| href, | ||
| ...props | ||
| }: OAuthButtonProps) { | ||
| const meta = CAuth.OAUTH_PROVIDERS[provider]; | ||
| if (!meta) return null; | ||
|
|
||
| return ( | ||
| <Button | ||
| type="button" | ||
| size={meta.iconSrc ? 'icon' : 'default'} | ||
| variant={'outline'} | ||
| className={cn(meta.buttonClassName, className)} | ||
| {...props} | ||
| > | ||
| <Link href={href} className="text-base"> | ||
| {meta.iconSrc ? ( | ||
| <Image | ||
| src={meta.iconSrc} | ||
| alt={meta.label} | ||
| width={24} | ||
| height={24} | ||
| className={cn('size-6', iconClassName)} | ||
| /> | ||
| ) : ( | ||
| meta.label | ||
| )} | ||
| </Link> | ||
| </Button> | ||
| ); | ||
| } |
This file was deleted.
Oops, something went wrong.
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.
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.
Как-то странно, что ты его глобально вынес, думаю лучше на уровне авторизации посадить это