-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add Auth layer in ui #171
Labels
ui
Something about UI
Comments
2wheeh
added a commit
that referenced
this issue
Feb 13, 2024
[#171] Make Button for sign in and out work
auth 관련 데이터를 nextjs 서버에서 다룰지에대한 결정은 나중으로 미루기로했습니다. 서버에서 auth 를 다루게 될 경우 확인이 필요한 부분:
간단한 구현예시: 'use server';
import { redirect } from 'next/navigation';
import { cookies } from 'next/headers';
import { GetUserDetailResponse } from '@/lib/definitions/user';
export async function signIn() {
redirect('/api/v1/google/sign-in');
}
export async function signOut() {
const res = await fetch(`${process.env.BACKEND_URL}/api/v1/auth/sign-out`);
if (res.ok) {
cookies().set('mrcToken', '', { expires: new Date(0) });
}
}
export async function getUserInfo() {
const mrcToken = cookies().get('mrcToken')?.value;
if (!mrcToken) return null;
const response = await fetch(`${process.env.BACKEND_URL}/api/v1/users/self`, {
headers: { authorization: `Bearer ${mrcToken}` },
});
if (!response.ok) {
// handle error properly
return null;
}
return (await response.json()) as { user: GetUserDetailResponse };
} import Text from '@/components/atomic/text';
import { signOut, signIn, getUserInfo } from '@/lib/actions/auth';
export async function ServerSignButton() {
const isLoggedIn = !!(await getUserInfo());
if (isLoggedIn) {
return (
<form
action={async () => {
'use server';
await signOut();
}}
>
<button>
<Text size="lg" weight="medium">
Sign Out
</Text>
</button>
</form>
);
}
return (
<form
action={async () => {
'use server';
await signIn();
}}
>
<button>
<Text size="lg" weight="medium">
Sign In
</Text>
</button>
</form>
);
} |
This was referenced Feb 15, 2024
Closed
Merged
2wheeh
added a commit
that referenced
this issue
Mar 12, 2024
…tect-route [#171] Protect route on client side
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Content
The text was updated successfully, but these errors were encountered: