parent
1be94c67c1
commit
f5553435b8
@ -1,8 +0,0 @@
|
||||
import { setCookie } from 'nookies';
|
||||
|
||||
export function setAccessToken(token: string) {
|
||||
setCookie(null, 'token', token, {
|
||||
maxAge: 7 * 24 * 60 * 60,
|
||||
path: '/',
|
||||
});
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
import { setCookie, destroyCookie } from 'nookies';
|
||||
|
||||
export function setAccessToken(token: string) {
|
||||
setCookie(null, 'token', token, {
|
||||
maxAge: 7 * 24 * 60 * 60,
|
||||
path: '/',
|
||||
});
|
||||
}
|
||||
|
||||
export function clearAccessToken() {
|
||||
destroyCookie(null, 'token', { path: '/' });
|
||||
}
|
@ -1,2 +1,6 @@
|
||||
export * from './cache';
|
||||
export * from './helpers';
|
||||
export * from './wrapper';
|
||||
export * from './login';
|
||||
export * from './time';
|
||||
export * from './ua';
|
||||
export * from './ui';
|
||||
|
@ -1,8 +1,15 @@
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
|
||||
import { clearAccessToken } from '@/utils';
|
||||
|
||||
export const useLoginRedirect = () => {
|
||||
const searchParams = useSearchParams();
|
||||
const redirect = searchParams.get('redirect');
|
||||
if (!redirect) return '/';
|
||||
return redirect;
|
||||
};
|
||||
|
||||
export const logout = () => {
|
||||
clearAccessToken();
|
||||
localStorage.clear();
|
||||
};
|
||||
|
@ -1,8 +0,0 @@
|
||||
import { destroyCookie } from 'nookies';
|
||||
|
||||
const logout = () => {
|
||||
destroyCookie(null, 'token', { path: '/' });
|
||||
localStorage.clear();
|
||||
};
|
||||
|
||||
export default logout;
|
@ -1,18 +0,0 @@
|
||||
export const headerContentType = {
|
||||
form: {
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
},
|
||||
json: {
|
||||
headers: { 'Content-Type': 'application/json; charset=utf-8' },
|
||||
},
|
||||
};
|
||||
|
||||
export const createFormBody: (formDataObject: any) => string = (formDataObject: any) => {
|
||||
const encodedForm = new URLSearchParams();
|
||||
for (const key in formDataObject) {
|
||||
if (formDataObject.hasOwnProperty(key)) {
|
||||
encodedForm.append(key, formDataObject[key]);
|
||||
}
|
||||
}
|
||||
return encodedForm.toString();
|
||||
};
|
Loading…
Reference in new issue