{"id":18308631,"url":"https://github.com/ariomoklo/hansip-old","last_synced_at":"2026-04-28T11:01:52.242Z","repository":{"id":58307436,"uuid":"530624793","full_name":"ariomoklo/hansip-old","owner":"ariomoklo","description":"Authorization library for building SSR app.","archived":false,"fork":false,"pushed_at":"2022-11-06T16:45:53.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T11:46:27.308Z","etag":null,"topics":["astro","auth","authorization","cookie","jwt","nuxt","ssr"],"latest_commit_sha":null,"homepage":"","language":"Astro","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ariomoklo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-30T11:25:14.000Z","updated_at":"2023-10-02T14:30:02.000Z","dependencies_parsed_at":"2022-08-31T21:14:08.210Z","dependency_job_id":null,"html_url":"https://github.com/ariomoklo/hansip-old","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/ariomoklo/hansip-old","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariomoklo%2Fhansip-old","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariomoklo%2Fhansip-old/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariomoklo%2Fhansip-old/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariomoklo%2Fhansip-old/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ariomoklo","download_url":"https://codeload.github.com/ariomoklo/hansip-old/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariomoklo%2Fhansip-old/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32377599,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T09:24:15.638Z","status":"ssl_error","status_checked_at":"2026-04-28T09:24:15.071Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["astro","auth","authorization","cookie","jwt","nuxt","ssr"],"created_at":"2024-11-05T16:08:38.100Z","updated_at":"2026-04-28T11:01:52.227Z","avatar_url":"https://github.com/ariomoklo.png","language":"Astro","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hansip\n\nAuthorization library for building SSR app.\n\nHansip adalah authorisasi library. Konsep dari hansip adalah authentikasi haruslah berasal dari API dan aplikasi front-end hanya melakukan authorisasi terhadap token yang diberikan oleh API. Hansip akan mencari token dalam cookie / header / url mengikuti kebutuhan mu.\n\n\u003e\n\u003e this package is not stable.\n\u003e\n\u003e use with your own risk.\n\u003e \n\n## Usage\n\n\u003e\n\u003e install hansip as dependency\n\u003e\n\u003e `npm install hansip` | `yarn add hansip` | `pnpm add hansip`\n\u003e\n\n### createCookieSession\n\n``` ts\nimport { createCookieSession } from 'hansip'\n\n// get your cookie\nconst cookie = request.headers.get('cookie')\nconst session = createCookieSession({\n  cookie: cookie,\n  tokenName: 'token',      // cookie name for jwt token.\n  refreshName: 'refresh',  // token refresh name. optional\n  cookieOptions: { \n    /**\n      \n      check cookie.serialize options for detailed info\n      @link https://www.npmjs.com/package/cookie\n\n      domain?: string | undefined,\n      expires?: Date | undefined,\n      httpOnly?: boolean | undefined,\n      maxAge?: number | undefined,\n      path?: string | undefined,\n      priority?: 'low' | 'medium' | 'high' | undefined,\n      sameSite?: true | false | 'lax' | 'strict' | 'none' | undefined,\n      secure?: boolean | undefined,\n    */\n  }\n})\n\nconst { token } = session.get()\n\n// do anything you want with token.\nif (!token) {\n  // redirect on token not found or validation false\n  return redirect()\n}\n\nresponse.headers.set('Set-Cookie', session.serialize.token())\nresponse.headers.set('Set-Cookie', session.serialize.refresh())\n// send response with token in cookie\n\n```\n\n### detectURL\n\n``` ts\nimport { detectURL, createCookieSession } from 'hansip'\n\nconst session = createCookieSession({ tokenName: 'token' })\nconst url = new URL(request.url, 'http://localhost')\n\nconst found = detectURL(url, { tokenName: 'access_token', refreshName: 'refresh_token' })\nif (!found.token) {\n  // redirect on token undefined\n}\n\n// do anything you want with token and refresh token\nconst validatedToken = found.token\nif (!validatedToken) {\n  // if token not valid redirect\n}\n\nsession.set(validatedToken, validatedToken)\nresponse.headers.set('Set-Cookie', session.serialize.token())\nresponse.headers.set('Set-Cookie', session.serialize.refresh())\n// send response with token in cookie\n```\n\n## Target\n\n- [ ] JWT utility / helper\n- [ ] ... ?","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fariomoklo%2Fhansip-old","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fariomoklo%2Fhansip-old","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fariomoklo%2Fhansip-old/lists"}